Updated from 4:15 p.m. EDT

Stocks in the U.S. closed to the upside Wednesday, but selling pressure in the final hour left the major averages well below their best levels of the day.

For most of the session, the indices rallied amid cooler-than-expected inflationary data and results at Freddie Mac ( FRE) that weren't nearly as bad as analysts had predicted. However, by the close, the Dow Jones Industrial Average had given up more than half its gains and was ahead by 66.2 points, or 0.52%, to 12,898.38.

The S&P 500 added 5.62 points, or 0.4%, to 1408.66. The Nasdaq Composite, which outperformed for much of the day, in the end barely held onto positive territory as big tech names Google ( GOOG), Apple ( AAPL) and Amazon.com ( AMZN) saw weakness in the last hour of trading. The index edged up 1.58 points, or 0.06%, to 2497.

The late fade notwithstanding, Steven Sheldon, CFA and principal with SMS Capital Management, called the day's action a "relief rally" in response to the encouraging consumer price numbers, since trepidation about inflation has been fairly prevalent among investors.

The Labor Department said that, despite a 0.9% jump in food costs -- the biggest advance in nearly two decades -- April consumer prices rose only 0.2% from the prior month. Economists had been looking for a 0.3% uptick. The core consumer price index, which excludes food and energy, rose 0.1%, or half of the expected increase.

Energy prices, the government said, were unchanged from March. Year over year, core consumer inflation was up 2.3%, a bit lower than anticipated, while the overall CPI climbed 3.9% from a year ago.

"People know the headline numbers are going to be bad, but they're saying, 'So what, if it doesn't bleed out and take in core numbers?" said Jim Paulsen, chief investment strategist with Wells Capital Management, "How long have we had this story about how oil prices are going to bleed out?"

Sheldon suggested that, as oil and food spikes deplete discretionary spending, the higher commodities prices may even be having the effect of keeping a lid on the rest.

At the same time, fed funds futures were pricing in odds of just 8% that the Federal Reserve will cut its overnight lending rate by another 25 basis points at its June 25 gathering. The fed funds target rate, which currently stands at 2%, has been pared back by 325 basis points since September in an effort to put a floor under deteriorating economic growth.

The chance for an August easing has all but vanished, signaling that the market anticipates that an economic recovery will have gained enough traction by then virtually to eliminate the need for more Fed support. The expectations for a quarter-point hike in December, moreover, are on the rise.

In less upbeat economic data, RealtyTrac said that foreclosures reached 243,353 in April, which the report noted will add pressure to housing prices that have already dropped. The report said areas of California, Florida, Nevada and Arizona continue to be "particularly hard-hit."

Breadth was positive. Roughly 1.97 billion shares changed hands on the New York Stock Exchange, with advancing issues outpacing decliners by a 3-to-2 margin. Volume reached about 2.11 billion shares on the Nasdaq, as winners just barely squeaked past losers.

On the equities side, Freddie Mac said its first-quarter loss narrowed to $151 million, or 66 cents a share, from a $3.97 loss in the fourth quarter -- far better than the average projection of 93 cents a share. Still, the loss was also nearly double that of last year, and the company plans to raise $5.5 billion "in the near future."

The stock ramped up 9.2%. Fellow government-sponsored mortgage buyer Fannie Mae ( FNM) was ahead by 6.3%.

Elsewhere in the financial space, Bloomberg reported that JPMorgan Chase ( JPM) could fire 4,000 of its own workers as the brokerage combines its operations with Bear Stearns ( BSC) and deals with the tough investment-banking environment, according to a person familiar with the matter.

Roughly 2,000 employees would be replaced by Bear-derived newcomers, said the report. JPMorgan shares were up 1%.

Department-store chain Macy's ( M), meanwhile, posted a surprise adjusted profit of 2 cents a share and reiterated its bullish full-year earnings forecast. When counting in substantial one-time restructuring and litigation charges, the company swung to a quarterly loss, but the stock still moved up 3.6%.

Elsewhere, chipmaking-equipment seller Applied Materials ( AMAT) said earnings dwindled by 26% last quarter, though the company beat on both top and bottom lines. Also, in a conference call, CEO Mike Splinter predicted more softness in chip-related spending while also offering his prediction that "this is the bottom." Shares spent most of the day in negative territory, but managed to finish marginally higher at $19.90.

Electronic Arts ( ERTS), a video-game publisher, offered a weaker full-year profit outlook than what was targeted by Wall Street. The company also came in well ahead of expectations for the fiscal fourth quarter with adjusted earnings of $30 million, or 9 cents a share, on 50% higher sales. Still, shares shed 3.7%.

Away from the tech patch, Whole Foods ( WFMI) plunged 13.9% after the organic-foods mart said costs from its Wild Oats buyout ate into its fiscal second-quarter profit, which slid 13%, even as revenue soared by 27.6%. Same-store sales, or those from locations open a year or more, climbed 6.7%.

Also, Deere & Co.'s ( DE) fiscal second-quarter income, which surged amid strong demand for the company's farm equipment, came in just short of consensus. The tractor maker also said that rising commodity prices will probably drag on its results for the rest of the year. Shares slumped 9.9%

Late in the trading day Tuesday, Clear Channel Communications ( CCU) reached a buyout settlement with Thomas H. Lee Partners and Bain Capital worth $36 a share, or $17.9 billion. That's $3.20 a share lower than what the companies had previously agreed on, but shares closed Tuesday higher and added 1.5% in the new session.

Among commodities, crude oil sank $1.58 to $124.22 a barrel as the Energy Information Administration reported that crude stockpiles rose by 200,000 barrels last week. Gold futures gave up $3.10 to $866.50 an ounce. The U.S. dollar firmed by 0.1% against the euro to $1.5457, while adding 0.5% against the yen at 105.30.

Treasury prices were on the rise again. The 10-year note ticked up 3/32 in price to yield 3.91%, and the 30-year bond rose 15/32 in price, yielding 4.61%.

Markets abroad were almost uniformly rising. In Asia, Hong Kong's Hang Seng Index slipped 0.1% overnight, but the Nikkei 225 in Tokyo climbed 1.2%. As for Europe, London's FTSE 100 ticked up 0.1% and Germany's Xetra Dax gained 0.3%. The Paris Cac jumped 1.1%.

More from Markets

Stocks Trade Mixed, Energy Shares Fall on Sharp Drop in Oil Prices

Stocks Trade Mixed, Energy Shares Fall on Sharp Drop in Oil Prices

Best Buy's Billionaire Founder: We Were 'Late to the Game' in Online Shopping

Best Buy's Billionaire Founder: We Were 'Late to the Game' in Online Shopping

Jim Cramer: Intuit Had a Fantastic Quarter

Jim Cramer: Intuit Had a Fantastic Quarter

Jim Cramer on Foot Locker's Earnings: Nike Is a Buy

Jim Cramer on Foot Locker's Earnings: Nike Is a Buy

Jim Cramer: The 10-Year Yield Could Go to 2.75%

Jim Cramer: The 10-Year Yield Could Go to 2.75%