The rally was remarkably fast - the Dow Jones industrial average was still down for the day with less than an hour of trading to go - and enough to erase two-thirds of its decline the day before.
The Fed set its target for interest rates near zero in 2008 as a response to the financial crisis that fall. Since then, it had said only that rates would stay low for an "extended period." On Tuesday, it guaranteed them until mid-2013.
But it was also a sign that the Fed expects the economy to stay weak for two more years, longer than the Fed had previously indicated. It has already been more than two years since the end of the Great Recession.
The central bank left open the possibility of a third round of bond purchases designed to hold interest rates down and push stock prices up. The second round, announced last year, led to an extended rally for the stock market.
In an unusually volatile day of trading, the Dow finished up 429.92 points, or about 4 percent. It closed at 11,239.77. The Standard & Poor's 500 index finished up 4.7 percent, and the Nasdaq finished up 5.3 percent.
The yield on the 10-year Treasury bond briefly hit a record low, 2.03 percent. Investors have bought government bonds, driving the yields down, even after S&P stripped the United States of its top-of-the-line credit rating last week.
Low interest rates for two more years could make the stock market a better bet because bonds will return less money. That appeared to be at least part of the reason stocks rallied so much after investors had a chance to digest the Fed's statement.
Some analysts also attributed the late-day rally to wording in the Fed's statement suggesting it might take further steps to stimulate the economy in the future.
The stock rally came after two and a half weeks of almost uninterrupted declines. Those were fueled first by uncertainty about the federal debt ceiling, then by concerns that the U.S. economy is headed for a new recession and about out-of-control European debt.
When it came late Friday, the downgrade only added anxiety. On Monday, the first day of trading after it was announced, the Dow fell 634 points. Even counting Tuesday's gains, the Dow is down 11.6 percent since July 21 - almost 1,500 points.
The Fed's announcement of a two-year timeframe for any rate increase underscored a stark reality: A sluggish economy and painfully high unemployment have become chronic.
"The tone of the Fed's statement is very downbeat. They are very nervous about the economy," said Mark Zandi, chief economist at Moody's Analytics. "This is unprecedented for the Fed to indicate they are ready to keep rates low for two more years."
Not everyone was as impressed as investors on Wall Street appeared to be. University of Oregon economist Timothy Duy called the move "weak medicine" and said he wanted to see the Fed commit to buying more Treasury bonds.
The Fed did hold out the promise of further help down the road but did not spell out what else it might do.
The central bank's decision was approved on a 7-3 vote with three Fed regional bank presidents who have been worried about inflation objecting. It was the first time since November 1992 that as many as three Fed members have dissented from a policy statement.
Dean Maki, chief U.S. economist at Barclays Capital, said the dissent suggests that Fed Chairman Ben Bernanke would have trouble building consensus for another round of bond purchases.
The Fed used significantly more downbeat language to describe current economic conditions. It said so far this year the economy has grown "considerably slower" than the Fed had expected and consumer spending "has flattened out."
It also said that temporary factors, such as high energy prices and the Japan crisis, only accounted for "some of the recent weakness" in economic activity.
The more explicit time frame on the Fed's key interest rate is aimed at calming nervous investors. It offered them a clearer picture of how long they will be able to obtain ultra-cheap credit.
Bernanke didn't speak publicly after Tuesday's Fed meeting. He is expected to speak later this month at the Fed's annual retreat in Jackson Hole, Wyo., Bernanke will likely address the weakening economy, the S&P downgrade and the market turmoil.
AP Economics Writer Christopher S. Rugaber contributed to this report.