Markets stayed largely calm throughout the drama in Washington, with the S&P 500 actually gaining 2.4 percent since the shutdown began Oct. 1, after House Republicans demanded changes to President Barack Obama's health care law before passing a budget.
Wall Street gambled 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 before the Thursday deadline.
If the deal wraps up soon, investors can turn their attention back to economic basics like third-quarter earnings. Overall earnings at companies in the S&P 500 index are 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 will 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.
Despite broad confidence that the political parties would strike a deal, 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 mean missing out on a rally after Washington came to an agreement. Investors have also become 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. could go over the "fiscal cliff" as lawmakers argued over a series of automatic government spending cuts. Stocks rebounded and began a strong rally that has propelled the S&P 500 up almost 21 percent this year.
Some were glad that investors could now turn their focus back to the traditional drivers of the market rather than worrying whether the latest dispatch from Washington would shake stocks.