Stocks added to session highs in the final hour, recovering from some of the devastating losses suffered over the past two days as the shock of a Brexit began to fade.

The S&P 500 was up 1.7%, the Dow Jones Industrial Average rose 1.4%, and the Nasdaq climbed 2.1%. Benchmark indexes remained in the red for the year. 

The two-day selloff in global markets wiped out $3 trillion in market capitalization on the Brexit shock. The pound plummeted to its lowest level in 30 years on Monday, driving the greenback higher and pushing crude oil prices to their worst settlement in a week.

The S&P 500 fell more than 5% over the past two days after the United Kingdom voted to leave the European Union. The move has far-reaching political and economic consequences as new trade deals and regulations begin to get drawn up over the next two years. Both Standard & Poor's and Fitch lowered their ratings on U.K. debt on Monday.

"After a strong two-day reaction to Britain's vote to leave the European Union, a range of markets are staging price corrections, with equities surging and the U.S. dollar declining from the levels reached on Monday," said Citi's Timothy Evans. 

Talk of further accommodation from global central banks appeared to boost investor appetite on Tuesday. Hopes have begun to rise that the Bank of England and the Bank of Japan could offer further stimulus in the wake of the uncertainty in Europe. Since Friday, the chances of a rate hike from the Federal Reserve this year have become unlikely, according to CME Group fed funds futures.

Crude oil recovered on Tuesday after also participating in the two-day selloff. The commodity had been under pressure as the greenback soared, deterring foreign purchases of U.S.-produced oil. West Texas Intermediate crude oil was up 3.3% to $47.85 a barrel on Tuesday.

"Crude futures are heading higher ... as prices attempt to join global equity markets in the effort to recover from two days of Brexit-induced selling," Robbie Fraser, commodity analyst at Schneider Electric, wrote in a note. "While currency fluctuations are always an important factor for crude prices, the relationship has been particularly significant of late, as a historic plunge for the pound and euro propped up the value of the US dollar."

The energy sector was leading market gains. Major oilers Exxon Mobil (XOM - Get Report) , Royal Dutch Shell (RDS.A - Get Report) , Chevron (CVX - Get Report) , PetroChina (PTR - Get Report) , Total (TOT - Get Report) and BP (BP - Get Report) were higher, while the Energy Select Sector SPDR ETF (XLE - Get Report) added 2.5%.

The British government has abandoned plans to sell its stakes in Royal Bank of Scotland (RBS) and Lloyds Banking Group (LYG) this year in the wake of the Brexit vote, according to sources, Reuters reported. The government had hoped to reduce its exposure to the banks it took over during the financial crisis, raising roughly 9 billion euros through stock sales.

First-quarter U.S. gross domestic product was raised to 1.1% growth in the third and final reading on Tuesday morning. First-quarter GDP has previously been estimated at 0.8%. Consumer spending was reduced, while exports were revised to show a slight gain over a previously estimated decline.

The U.S. economy suffered an economic slowdown at the beginning of the year as cautious consumers opted to save rather than spend, a strong U.S. dollar and weaker overseas demand hampered U.S. manufacturing, and energy prices continued to weigh on the sector.

Home prices continued to climb in April, though at a slightly slower pace than in March, according to the S&P Case-Shiller Home Price Index. Prices rose 5% over the past 12 months ending April, less than 5.1% growth in March. Tight inventory and strong demand have driven home prices in the past year.

Consumer confidence in the U.S. improved in June at a far-faster pace than analysts expected. The Conference Board's index climbed to a reading of 98 this month, up from a revised 92.6 in May and well above expectations for a reading of 93.3. The improvement is a surprise, conflicting with a separate survey from the University of Michigan which showed a deterioration in sentiment.