NEW YORK -- Wall Street finally got the deal it's been waiting for.
A last-minute agreement to keep the U.S. from defaulting on its debt and reopen the government sent the stock market soaring Wednesday, pushing the Standard & Poor's 500 index close to a record high.
On Wednesday, Senate leaders agreed to fund the government through Jan. 15 and extend government borrowing through Feb. 7.
The Senate deal was reached just hours before a Thursday deadline that Treasury Secretary Jacob Lew had set to raise the $16.7 trillion debt limit. The government has been partially shut for 16 days because House Republicans had demanded changes to President Barack Obama's health care law before passing a budget.
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.
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.
"It's a little bit silly in the short term for markets to go down so much on press conferences and then to go up so much on rumors," said Brad Sorensen, director of market and sector research at the Schwab Center for Financial Research. "We've urged investors to pull back a little bit and look at the longer term."
The market for U.S. Treasury bills reflected relief among bond investors. The yield on the one-month T-bill dropped to 0.13 percent from 0.40 percent Wednesday morning, an extraordinarily large move. The decline means that investors consider the bill, which would have come due around the time a default may have occurred, to be less risky.
The yield on the 10-year Treasury note edged down to 2.67 percent from 2.74 percent Tuesday. Yields on longer-term U.S. government debt haven't moved as much as those on short-term debt because investors believed that the government would work out a longer-term solution.
Among stocks making big moves:
• Bank of America rose 32 cents, or 2.2 percent, to $14.56 after the second-largest U.S. bank reported a surge in third-quarter earnings.
• Stanley Black & Decker plunged $12.70, or 14.3 percent, to $76.75 after the company lowered its profit forecast for the year, citing slower growth in emerging markets and a hit from the U.S. government shutdown.