The agreement follows a month of political gridlock that threatened to make America a deadbeat and derail global financial markets. Investors have stayed largely calm throughout in the current drama in Washington, with the S&P 500 actually gaining 2.4 percent since the shutdown began on Oct. 1.
Wall Street had bet that politicians wouldn't let the U.S. default, a calamity economists said could paralyze lending and push the economy into another recession.
"We knew it was going to be dramatic, but the consequences of a U.S. default are just so severe that the base case was always that a compromise was going to be reached," said Tom Franks, a managing director at TIAA CREF, a large retirement funds manager.
Congress was racing to pass the legislation Wednesday.
If the deal wraps up soon, investors can turn their attention back to basics like earnings and the economy. Corporations have begun to report third-quarter earnings, but Wall Street has been glued to the budget brinksmanship. Overall earnings at companies in the S&P 500 index is forecast to grow 3.1 percent from a year earlier, according to data from S&P Capital IQ. That's slower than the growth of 4.9 percent in the second quarter and 5.2 percent in the first quarter.
It'll be harder for Wall Street to get an up-to-date view of the economy because the partial government shutdown that began Oct. 1 has kept agencies from releasing key reports on trends like hiring. In general, though, the economy has been expanding this year.
Traders have been correctly betting that Washington would reach a deal. To be sure, the Dow went through rough patches over the last month, at one point falling as much as 900 points below an all-time high reached on Sept. 18. The Dow has seen seven triple-digit moves in the last 10 trading days.
On Wednesday, the Dow Jones climbed 205.82 points, or 1.4 percent, to 15,373.83. The S&P 500 gained 23.48, or 1.4 percent, at 1,721.54. That's only four points below its record close of 1,725.52 set Sept. 18.
The Nasdaq composite climbed 45.42, or 1.2 percent, to 3,839.43.
The feeling among stock traders in recent days was that panicking and pulling money out of stocks could leave them missing out on a rally after Washington finally came to an agreement. Investors are also becoming inured to Washington's habit of reaching budget and debt deals at the last minute.
"Investors have become, unfortunately, accustomed to some of the dysfunction," said Eric Wiegand, a senior portfolio manager at U.S. Bank. "It's become more the norm than the exception."
In the summer of 2011, the S&P 500 index plunged 17 percent between early July and early August as lawmakers argued over raising the debt limit and Standard & Poor's cut the U.S. credit rating from 'AAA,' its highest ranking. The market later recovered.
Stocks also slumped in the last two weeks of 2012 as investors fretted that the U.S. would go over the "fiscal cliff" as lawmakers argued over a series of automatic government spending cuts. Stock also rebounded and embarked on a strong rally that has pushed the S&P 500 up almost 21 percent this year.