Stocks ended higher after an afternoon rally as materials and retail stocks rose, despite ongoing conflicts in the Middle East, and uncertainty about the outcome of the nuclear disaster in Japan.
The Dow Jones Industrial Average rose 67.39 points, or 0.6 percent, to close at 12,086.02, after trading in negative territory all morning. The blue-chip index fell slightly in the previous session following three days of strong gains.
Among Dow components, Alcoa and Disney gained, while Bank of America and Wal-Mart slipped.
The S&P 500 gained 3.77 points, or 0.3 percent, to close at 1,297.54, while the tech-heavy Nasdaq rose 14.43 points, or 0.5 percent, to close at 2,698.30. The CBOE Volatility Index, widely considered the best gauge of fear in the market, fell to near 19.
Of the key S&P 500 sectors, materials, consumer discretionary and technology rose, while financials and health care declined.
"The money put to work today was by investors bullish on the global economic recovery continuing," said Michael Sheldon, chief market strategist at RDM Financial. "Those investors probably believe current risks are not enough to derail the recovery."
But Kenneth Polcari, managing director at ICAP Equities, said the move higher reflected technical factors more than fundamentals. As Polcari pointed out, stocks started to move higher after the S&P 500 hit 1,284. From there, the index kept rising until it touched 1,300, and it then turned slightly lower.
The move, however, reflected "no real thrust of commitment," Polcari said, noting that volume was very light. In the final hour of trading, only 650 million shares changed hands on the floor of the New York Stock Exchange.
Polcari expects the market will continue to trade between 1,300 on the S&P 500 and 1,220, its 200-day moving average, until a catalyst such as strong earnings or a clear outcome in Libya moves the market decisively in one direction or another. But with stocks trading close to their two-year highs, the market could easily fall, especially if it becomes clear the Federal Reserve is not going to continue stimulating the economy.
"If the Fed walks away, the market gets a fairly decent correction," Polcari said.
Meanwhile, Bill Miller, chief investment officer and portfolio manager of Legg Mason Capital Management, told CNBC that the stock market is 20 percent undervalued.
Earlier, well-known stock analyst Laszlo Birinyi, head of Birinyi Associates, said on CNBC that stocks were only half way through a bull market, and so the S&P 500 index could rise another 60 percent over the next two to three years.
"The last bull market was five years," Birinyi said. "We're still looking for (this) bull market to last four to five years. If we cobble together all the long bull markets, we come up with a historical projection of about 2,100 out two or three years from now on the S&P."
Oil pricesrose as tensions in the Middle East and North Africa continued. London Brent crude closed below $116 a barrel, while U.S. light sweet crude closed above $105 a barrel. Crude oil inventories rose by 2.1 million barrels, according to the Department of Energy. Gasoline inventories fell by 5.3 million.
Gold rose to nearly $1,438 an ounce, hitting its highest level since early March and silver struck a 31-year peak, as investors sheltered in precious metals following a key vote threatening Portugal's government. Freeport McMoRan shares advanced more than 4 percent as metals rose. Newmont Miningand United States Steel also gained, as did Alcoa.