Stocks gained on optimistic prospects for a Greek bailout and despite several economic reports confirming a slowdown in the U.S. economy.
The Dow Jones Industrial Average gained more than 50 points after rising more than 120 earlier, and ending lower for fourth straight week on Friday.
Most Dow components gained, with Intel among the lead performers. The chip-maker unveiled a new category of laptops its calling Ultrabooks at a trade show in Taiwan.
TheS&P 500 and the Nasdaq also rose about a half a percent. The CBOE Volatility Index, widely considered the best gauge of fear in the market, rose above 16.
All key S&P 500 sectors gained, led by health care, technology and energy.
The brighter performance for stocks on the last day of the month is unlikely to turn around the market's negative performance in May. As of Friday, the Dow was down nearly 3 percent, the S&P 500 was down 2.4 percent, and the Nasdaq was down 2.7 percent. All major indices remain higher for the year, however.
If history is a guide, stocks won't turn around in June. The Dow has fallen for the last six Junes, and has been up only twice since 2000. Overall, the market has been down in June in the last four years.
Tuesday's performance owes much to a decision by some officials in Germany to allow Greece to restructure its debt, the Wall Street Journal reported over the weekend. That news encouraged investors concerned about Greece's future.
Investors pushed the euro to a three-week high against the dollar on the news, and oil prices also gained. U.S. Light Sweet Crude rose above $102 a barrel, while in London, Brent crude rose above $116.