NEW YORK - This time, the stock market had a late-day rally.

Most stocks surged in the final hour of trading Tuesday to give the Dow Jones industrials a gain of 123 points. That ended a two-day slump that sent the Dow down nearly 440 to a seven-month low.

Federal Reserve Chairman Ben Bernanke set the tone for the day by saying he didn't expect the economy to go back into recession.

As was also the case Monday, there was no one catalyst for the late move. But the late rally itself drew buyers who had waited to see whether stocks would slide again before the close. Computer programs also kicked in, with rising stocks triggering more buying - the reverse of the computer selling seen the last two days.

Materials stocks rose after gold extended its gain, briefly touching a record $1,254.50. Wilmington chemical maker DuPont climbed 4.1 percent. Meanwhile, oil drilling companies slumped after President Obama blasted the industry in an interview with NBC. Transocean, which owns the oil rig that exploded in the Gulf of Mexico and caused the spill, fell 5.8 percent.

The Dow rose 123.49, or 1.3 percent, to 9,939.98. The Dow had fallen 4.3 percent in the two prior days to its lowest level since Nov. 4.

The S&P 500 index rose 11.53, or 1.1 percent, to 1,062.00. It also fell Monday to its lowest close since November. The S&P's two-day slide of 5.4 percent was its steepest since March 2009.

The Nasdaq fell 3.33, or 0.2 percent, to 2,170.57.

Uncertainty about the global economy sent investors looking for safety in gold. There was less demand for the safety of Treasurys, however.

Crude oil rose 55 cents to $71.99 per barrel on the New York Mercantile Exchange.

Bernanke said in a speech late Monday that he expected the U.S. recovery to continue, but he acknowledged it was unlikely to be robust.

"It won't feel terrific," Bernanke said.

The Fed releases its Beige Book report Wednesday, which provides a regional snapshot of economic activity.

The chairman's comments reassured traders after Friday's disappointing May jobs report. Bernanke's assessment also eased worries that a slowdown in Europe would spread across the Atlantic.

Among chip stocks, Intel Corp. fell 13 cents, or 0.6 percent, to $20.18. Marvell Technology Group Ltd. fell 85 cents, or 4.7 percent, to $17.21, while Nvidia Corp. dropped 32 cents, or 2.8 percent, to $11.18.

Materials stocks got a boost from the rise in gold and a rebound in copper. DuPont rose $1.40, or 4.1 percent, to $35.49. Freeport-McMoRan Copper & Gold Inc. rose $2.82, or 4.8 percent, to $61.48.

Oil drilling companies fell after analysts also warned that a ban on deepwater drilling tied to the Gulf oil spill could be extended beyond six months. Obama's comments also brought more bad attention to drillers.

"I don't sit around just talking to experts because this is a college seminar, we talk to these folks because they potentially have the best answers - so I know whose ass to kick," Obama said.

Transocean Corp. fell $2.84, or 5.8 percent, to $46.33. Analysts lowered their ratings on Diamond Offshore Drilling. The stock fell $2.27, or 3.8 percent, to $56.94.

BP P.L.C., which operated the rig, fell $2.08, or 5.7 percent, to $34.68.