Wall Street ended less than 2 percent short of a record-high close on Wednesday as a rebound in oil prices added to optimism sparked by a raft of earnings reports.
Driven 15 percent higher since mid-February by a recovery in weak oil prices and helped by a softer dollar, the S&P 500 stood less than 30 points below last May's all-time peak.
Investors fixated on a parade of first-quarter results, including an upbeat report from VMWare and a disappointing scorecard from Coca-Cola.
Weighed down by the energy sector, first-quarter earnings at S&P 500 companies are expected to have slumped 7.5 percent on average, according to Thomson Reuters I/B/E/S.
Due to the market's recent oil-fuelled gains and the tempered outlook for corporate profits, the S&P 500 is trading at about 17.8 times expected earnings, its most expensive level since 2004, according to Thomson Reuters Datastream.
Crude on Wednesday gained about 2 percent after a report showed US inventories grew less than expected last week.
"It would be overly optimistic to assume it's clear sailing from here," said Alan Gayle, director of asset allocation at RidgeWorth Investments in Atlanta. "The good news has to keep on coming for this market to keep moving higher."
Data on Wednesday showed US home resales rose more than expected in March, pointing to a continued recovery in the housing market, despite signs of sluggish first-quarter economic growth.
The Dow Jones industrial average rose 0.24 percent to end at 18,096.27 points and the S&P 500 gained 0.08 percent to 2,102.4. The S&P earlier traded as high as 2,111 points.
The Nasdaq Composite added 0.16 percent to 4,948.13.
Five of the 10 major S&P sectors rose, led by an 0.89 percent rise in financials and an 0.8 percent increase in energy.
After the bell, Qualcomm reported a 19.5 percent drop in quarterly revenue and its stock lost 0.5 percent.
During the session, better-than-expected quarterly profits pushed several stocks higher, with VMWare jumping 13.74 percent, Discover Financial Services rallying 8.16 percent, St. Jude Medical gaining 3.99 percent and Yahoo rising 4.16 percent.
Coca-Cola fell 4.78 percent after sales dropped for the fourth straight quarter.
Lexmark jumped 9.38 percent after it agreed to be taken private by a group of investors led by China-based Apex Technology Co and PAG Asia Capital in a deal valued at $3.6 billion net of cash. Advancing issues outnumbered decliners on the NYSE by 1,708 to 1,284. On the Nasdaq, 1,541 issues rose and 1,250 fell.
The S&P 500 index showed 25 new 52-week highs and no new lows, while the Nasdaq recorded 56 new highs and 16 lows.
About 7.5 billion shares changed hands on US exchanges, above the 6.7 billion daily average for the past 20 trading days, according to Thomson Reuters data.