The gains were broad-based, with nine of 10 stock categories in the Standard & Poor's 500 rising, led by financial stocks. Bank of America gained 2.7 percent, best among the 30 stocks in the Dow. Utilities declined by a whisker. European stocks rose.
For once, investors had the Greek parliament to thank. On Sunday it approved sharp cuts in civil service jobs, welfare and the minimum wage, required by international leaders for a $170 billion bailout that Greece must have to avoid defaulting on its debt.
Other details of the bailout still need to be finalized, though. And rioting while Greece's parliament voted was a reminder that its financial problems are not solved. Germany also indicated it would take time before approving the bailout.
The Greek debt deal amounts to a default because creditors will get less than they are owed, said Peter Cardillo, chief market economist for Rockwell Global Capital.
Still, "orderly default is better than a chaotic default, which would lean on the whole eurozone and the global economy as well," he said, referring to the 17 countries that use the euro currency.
Cardillo said market gains may be muted for a while because of the social unrest in Greece and because stocks have already risen this year. The Dow is up 5.4 percent, the Standard & Poor's 500 7.5 percent.
In afternoon trading, the Dow was at 12,881, less than 10 points shy of its highest close since before the 2008 financial meltdown. The S&P rose 10 points to 1,352. The Nasdaq composite rose 27 points to 2,931.
The Greek debt deal appeared to take some pressure off U.S. banks. Moody's Investors Services said the $25 billion settlement between mortgage lenders and states over foreclosure practices is a negative for all five major banks involved.
Still, most major banks, which have varying levels of exposure in Europe, gained on Monday. JPMorgan Chase was up 1.4 percent and Citigroup 0.3 percent. Financial stocks have been the best performers in the S&P this year, gaining 13 percent.
The biggest gaining group of stocks on Monday was industrials, up 1.1 percent.
Shares of ATM maker Diebold Inc. rose 11 percent after it reported strong sales to banks, a sign they may be willing to spend more to upgrade their technology.
Apple crossed $500 per share for the first time, with a 1.5 percent rise to $501. Apple had been in a tight race with Exxon Mobil to be the world's biggest company by market value, but it is solidly ahead now -- $465 billion to $400 billion.
Worries about the global economy and the state of the U.S. recovery pushed stocks around during the second half of 2011, said Ralph Fogel, a partner and investment strategist for wealth management and advisory firm Fogel Neale Partners in New York. .
"The end of the world was coming," or so traders thought, he said. "It wasn't the end of the world. ... Then the market stopped listening."
The euro fell a fraction of a penny against the dollar, to $1.32.
Bond traders appeared skeptical that the cuts passed by the Greek parliament would be enough. Prices moved between small gains and losses. The yield rose to 1.99 percent from 1.98 percent late Friday.
In Europe, the FTSE 100 in Britain rose 0.9 percent to 5,906. Germany's DAX rose 0.7 percent to 6,738. The CAC-40 in France rose slightly to 3,385. In Athens, stocks rose 4.6 percent.
In Asia, Japan's Nikkei 225 closed 0.6 percent higher at 8,999, and Hong Kong's Hang Seng gained 0.5 percent.
Oil rose to $100.49 per barrel in New York. Gold rose slightly to $1,726.60 per ounce.
Among other stocks in the news:
-- Chesapeake Energy Corp. rose 2.4 percent after saying it will try to raise as much as $12 billion by selling assets to pay down debt.
-- Regeneron Pharmaceuticals Inc. rose almost 13 percent after it said sales of its eye drug Eylea should reach $300 million, up from its previous forecast of $160 million.
-- AmerisourceBergen Corp. fell 3.3 percent after the prescription drug distributor said its chief financial officer left to pursue other interests.