Energy stocks jumped, following the price of oil higher. Crude rebounded after dropping to its lowest level of the year in early trading. Industrial stocks also climbed sharply after Buffett's Berkshire Hathaway agreed to buy Precision Castparts, a maker of industrial components, for $32 billion.
The pace of corporate deal making has been surging this year as borrowing costs have stayed low, making it easier for companies to fund acquisitions. That tends to push up stock prices because buyers typically pay a premium to make the deal attractive to shareholders.
"Any time you have mergers and acquisitions, especially of this size, that's a good sign because corporate America is feeling good about the economic prospects," said Peter Cardillo, chief market economist at Rockwell Global Capital.
The Standard & Poor's 500 index rose 26.61 points, or 1.3 percent, to 2,104.18. It was the biggest gain for the index since May 8.
The Dow Jones industrial average rose 241.79 points, or 1.4 percent, to 17,615.17. The Nasdaq composite climbed 58.25 points, or 1.2 percent, to 5,101.80.
The gains also ended a seven-day losing streak for the Dow Jones industrial average, its longest run of losses in four years. Some mixed earnings reports and the slump in oil have weighed on the 30-member index in the past three weeks.
Some investors are also anticipating that the Federal Reserve may raise interest rates next month. That's unnerving for them because rates close to zero have been a major factor in driving a bull-market in stocks that has lasted for more than six years.
Precision Castparts was the biggest gainer in the S&P 500. The stock jumped $37.04, or 19 percent, to $230.92. Berkshire will pay $235 per share in cash for Precision Castparts' outstanding stock. The deal is valued at about $37.2 billion including debt.
Energy stocks were also among the biggest gainers as oil rose, rebounding from heavy losses last week. The sector jumped 3 percent as companies including Exxon Mobil and Chevron climbed.
The price of oil posted a strong gain after briefly dipping below its lowest close for the year. U.S. crude climbed $1.09 to close at $44.96 a barrel in New York. Early Monday oil dipped a penny below its $43.46 March 17 close, its lowest in six years. Brent crude, a benchmark for international oils used by many U.S. refineries, rose $1.80 to close at $50.41 in London.
Despite Monday's rebound, oil is still down almost 60 percent from its peak last year.
About 90 percent of the companies in the S&P 500 have reported their second-quarter results, and average earnings for companies in the index are flat for the period. However, that's masking a big slump in energy company earnings. If the energy sector is excluded, profits rose 7.7 percent, according to S&P Capital IQ data.
That's a good sign for some investors.
"Once you start digging into the numbers the only sector that is really messing things up is energy," said Brad McMillan, Chief Investment Officer for Commonwealth Financial Network. "Everything else is doing pretty well."
Twitter was another beaten-up stock that had a good day on Monday.
The social media company got a lift after the company signed a two-year content and advertising deal with the National Football League. Also, interim CEO and co-founder Jack Dorsey increased his stake in the embattled social media company.
Twitter, which has fallen sharply this year as its growth has disappointed investors, jumped $2.46, or 9.1 percent, to $29.50.
U.S. government bond prices fell. The yield on the benchmark 10-year Treasury note climbed to 2.23 percent from 2.17 percent on Friday. The dollar rose to 124.62 yen. The euro rose to $1.1019.
The price of gold rose $10 to $1,104.10 an ounce, silver gained 47 cents to $15.29 an ounce and copper increased seven cents to $2.40 a pound.
In other futures trading on the NYMEX:
— Wholesale gasoline rose 7.1 cents to close at $1.694 a gallon.
— Heating oil rose 4.8 cents to close at $1.592 a gallon.
— Natural gas rose 1.5 cents to close at $2.842 per 1,000 cubic feet.