NEW YORK (TheStreet) -- U.S. investors cheered an agreement between Greece and its European creditors following months of back-and-forth deliberations.

The development triggered a relief rally, helping Wall Street to close out its best three days since March. 

The S&P 500 rose 1.1%, the Dow Jones Industrial Average gained 1.2%, and the Nasdaq was up 1.5%.

European leaders agreed to a bailout of 86 billion euros ($95 billion) for Greece, though the country must impose strict spending cuts in exchange for the additional funds. The deal helps prevent Greece from exiting the eurozone, an unprecedented and potentially catastrophic outcome for the region.

"It's much better than anyone really expected," Kathleen Brooks, head of research at City Index, told TheStreet. "We were getting into a really desperate situation. By next Monday ... Greece had to repay the ECB 3.5 billion euros. It didn't have the money to do that so it has avoided another default. This has been certainly the best outcome and avoids that near-term default which would definitely have meant the collapse of the Greek banking sector."

The Greek chapter hasn't been closed yet, though, with the country's parliament still to vote on the deal's terms on Wednesday.

"There are still a variety of details to be agreed upon after the fact," wrote CRT Capital's David Ader and Ian Lyngen in a note. "Greek banks are still closed and the July 20 ECB payment of 4.2 billion euros looms ... We're apprehensive that although ostensibly a compromise has been reached, the market remains vulnerable to headlines related to the ultimate completion of the deal."

Microsoft(MSFT) - Get Report was one of the best performers on the Dow after setting a July 29 launch date for its new Windows 10 operating system. The software giant will provide its upgraded system to PC owners free of charge for a limited time. Shares jumped 2% to $45.52.

Netflix(NFLX) - Get Report closed at records on Monday after hitting an intraday high of $716.16 earlier in the session. Shares of the streaming giant gained 4% to $707.56, rallying in line with broad-market gains and ahead of its earnings report after the bell Wednesday. Shares beat the previous record close of $681.19 set in June.

Anacor Pharmaceuticals (ANAC) jumped 55% after preliminary data showed a positive response to its drug candidate for those suffering from atopic dermatitis, an itchy skin condition. The company expects to file a new drug application in the first half of 2016.

Remy International (REMY) spiked 42.3% on Monday after BorgWarner(BWA) - Get Report agreed to purchase the electrical component manufacturer for $950 million in cash. BorgWarner, an auto parts company, expects the deal to close by the fourth quarter.

Casino stocks with exposure to Macau were rallying alongside Chinese markets and on news Macau's government is considering easing smoking bans on casino floors. The latter action is likely in response to waning tourism at the gambling destination. Las Vegas Sands(LVS) - Get Report, Wynn Resorts(WYNN) - Get Report, Melco Crown (MPEL) and MGM Resorts(MGM) - Get Report were trading higher.