The Dow industrials closed lower for a sixth day Thursday on fears that credit markets may break down and hurt the economy and profits, but a remarkable late-day surge almost brought them back into the black.

The Dow Jones industrial average declined 15.69 points, or 0.12 percent, to 12,845.78. But the Standard & Poor's 500 Index was up 4.57 points, or 0.32 percent, at 1,411.27. The Nasdaq Composite Index was down 7.76 points, or 0.32 percent, at 2,451.07.

The blue chips recovered 300 points in the last 45 minutes of the day, and the broader benchmark S&P 500 clawed back into positive territory to finish up on the strength of a rebound in beaten-down bank and brokerage stocks.

Earlier, investor confidence had taken a blow from Countrywide Financial Corp. (CFC). The biggest U.S. mortgage lender said it had to draw down an entire $11.5 billion bank credit line after it was essentially shut out of other credit markets.

For the first time in the month-long slump, the companies bearing the brunt of the losses were those most sensitive to a potential downturn in economy, such as oil company Exxon Mobil (XOM) and industrial conglomerate Caterpillar (CAT) .

"I think the Countrywide news going into the day reinforced the fact that credit problems haven't run their course. The 'all's clear' bell hasn't been rung." said Eric Kuby, chief investment officer at North Star Investment Management Corp., in Chicago.

The Chicago Board Options Exchange Volatility Index briefly jumped intraday to 37.50, nearly a five-year high, on Thursday, indicating mounting uncertainty among investors on the direction of the stock market heading into August options expiration.

That uncertainty was a fertile breeding ground for all kinds of rumors — from chatter the Federal Reserve would cut rates to talk that Warren Buffett was about to snap up financial shares.

Financial shares' gains were helped by optimism that regulators may allow Fannie Mae and Freddie Mac , the two biggest U.S. mortgage funding companies, play a bigger role in steadying the ailing industry.

"I think many of the financials are oversold.You're starting to probably get some investors who are taking a longer-term viewpoint and looking for stocks that have gotten beaten up," said Michael Sheldon, chief market strategist at Spencer Clarke in New York.

An S&P index of financial shares rose 3.5 percent.

Trading was extremely heavy on the NYSE, with about 3 billion shares changing hands, well above last year's estimated daily average of 1.84 billion, while on Nasdaq, about 3.3 billion shares traded, substantially above last year's daily average of 2.02 billion.

Declining stocks outnumbered advancing ones by a ratio of about 8 to 5 on the NYSE and by 5 to 4 on Nasdaq.