The gains were broad. Nearly three stocks rose for every one that fell on the New York Stock Exchange. Every sector in the S&P 500 made gains, except utilities.

The Standard & Poor's 500 index rose 23 points, or 1.2 percent, to close at 2,099. The Dow Jones industrial average rose 217 points, or 1 percent, to 17,937, while the Nasdaq composite climbed 74 points, or 1.5 percent, to 5,072.

New Greece bailout deal with EU requires more cutbacks

European leaders reached a tentative agreement on new loans for Greece, removing an immediate threat that the country would default on its debts and leave the euro. Nine hours after a self-imposed deadline passed, European officials announced the breakthrough early Monday. In exchange for a three-year loan program, the deal requires Greece's parliament to pass tax increases and other key demands from its lenders into law by Wednesday

"Our markets have reason to cheer," said Tim Dreiling, senior portfolio manager at the U.S. Bank's Private Client Reserve. "It's a reprieve from worry for a few days at least."

Microsoft said it would roll out Windows 10 in late July. The upgraded operating system is supposed to allow users to switch seamlessly between personal computers and their gadgets. The company's stock gained 88 cents, or 2 percent, to $45.49, the biggest gain in the Dow.

Comcast, the country's largest cable company, announced plans to launch a streaming video service later this summer. The new service, called Stream, will cost $15 a month and allow customers to watch live TV from about a dozen networks, including HBO, on their phones, tablets and laptops. Comcast gained 54 cents, or 1 percent, to $63.73.

JPMorgan Chase, Johnson & Johnson and Wells Fargo will turn in their second-quarter results early Tuesday as the earnings season gets underway. Analysts expect overall earnings to fall 4.5 percent compared with the prior year, according to S&P Capital IQ. If that forecast comes true, it would mark the first drop in earnings since 2009.

Benchmark U.S. oil rose 16 cents to $52.90 a barrel on the New York Mercantile Exchange.

U.S. government bond prices slipped, pushing yields up. The yield on the 10-year Treasury note rose to 2.42 percent from 2.40 percent late Friday. The euro fell to $1.1026 while the dollar rose to 123.37 yen.