Updated for 4:16 p.m. EDT

Stocks were enjoying solid gains for much of the session Thursday, but afternoon weakness in the tech sector spoiled the run and the major averages ended the day lower.

The tech-heavy Nasdaq Composite rose by as many as 23 points before pulling back and settling down 39.41 points, or 1.4%, to 2772.20.

Among major tech names, Baidu.com ( BIDU), Infosys Technologies ( INFY), Research In Motion ( RIMM), Amazon.com ( AMZN), and SanDisk ( SNDK) dropped 5% or more.

"Investors have to be mindful of these tech companies and the recent rocket rise they've had," said Robert Pavlik, chief investment officer with Oaktree Asset Management. "There was a potential for a pullback, and there has been a lot of fast money that has poured into these names. These momentum traders have the ability to really push these stocks around."

The decline in tech stocks overshadowed positive news out of Wal-Mart ( WMT) and General Motors ( GM), both of which helped the blue chip averages set record intraday highs earlier.

When the closing bell rang, though, the Dow Jones Industrial Average had fallen 63.57 points, or 0.45%, to 14,015.12. The S&P 500 lost 8.06 points, or 0.5%, at 1554.41, having been up 14 earlier.

"Markets get skittish around new highs," said Steven Sheldon, principal with SMS Capital Management. "We were due to focus on bad news, having shrugged off a lot of that for so long. The market has been so strong that it's hard to get worked up over what could end up being a healthy pullback."

Leading the Dow to the downside were Alcoa ( AA), Boeing ( BA), Intel ( INTC), and Caterpillar ( CAT), all finishing lower by 1.7% or more.

Breadth was decidedly negative Thursday. On the New York Stock Exchange 3.36 billion shares changed hands, as decliners topped advancers by a 2-to-1 margin. Volume on the Nasdaq reached 2.50 billion shares, with losers outpacing winners nearly 11 to 4.

While the tech sector was the worst decliner, plenty of others finished in negative territory as well. The Amex Airline Index slid 1.5%, the S&P Retail Index lost 1.3%, and both the Dow Jones Transportation Average and the Nasdaq Biotechnology Index finished down 0.9%.

Stocks were also hit by statements from European Central Bank governor Axel Weber. He said the bank may need to resume interest rate hikes and push them to a "restrictive" level, even though the ECB has left rates unchanged recently.

Earlier in the session, Dow component Wal-Mart led gains after the retailer boosted its third-quarter profit guidance. The company posted a September comp sales increase of only 1.4%, a bit weaker than had been anticipated, and attributed the improved profit outlook to cost cuts. Shares of Wal-Mart rose $1.31, or 2.9%, to $46.90.

Most other retailers reported lackluster results for September. Target ( TGT) posted a September comp sales rise of 1.2%, compared with expectations of a 2.2% gain. Target was off $1.15, or 1.8%, to end at $64.62.

Apparel retailers were the worst retail performers for the month. Abercrombie & Fitch ( ANF), Gap ( GPS), Chico's FAS ( CHS) and Limited ( LTD) all reported monthly losses and missed consensus targets.

Aside from Wal-Mart, GM was a winner on the Dow. The automaker's shares surged 4.9% to $39.99, a new 52-week high, after the United Auto Workers union ratified a landmark labor deal with the company.

In earnings, PepsiCo ( PEP) reported a 17% advance in its third-quarter profit, easily topping the Thomson First Call estimate. However, shares ended down $1.83, or 2.5%, to $71.77.

Away from equities, commodity prices were on the rise. The weekly inventory report from the Energy Department showed an unexpected decline of 1.7 million barrels in crude stocks, and oil jumped $1.78 to $83.08 a barrel.

Gold futures were up $10.60 to $756.70 an ounce, and silver gained 12 cents to $13.98 an ounce.

On the economic front, the Commerce Department said that the August trade deficit fell to $57.6 billion from $59.0 billion, falling short of economists' estimates.

"The trade deficit still is about 5% of gross domestic product and remains a big drag on economic growth and incomes," said Peter Morici, professor at the University of Maryland School of Business and former Chief Economist at the U.S. International Trade Commission. "Simply, the trade deficit cannot be significantly reduced without curbing the U.S. appetite for imported goods, especially, petroleum, Chinese consumer goods and automobiles."

The Labor Department also released two separate reports. It said jobless claims fell to 308,000 from 320,000 last week, below the consensus 315,000. Also, its import price index slipped 0.2% last month, compared with a 0.1% decline in August.

Treasury prices were mixed. The 10-year note was up 3/32 in price, cutting the yield to 4.64%. The 30-year bond was down 1/32 to yield 4.87%.

Overseas markets were higher. In Asia, Hong Kong's Hang Seng rose 2%, and Japan's Nikkei 225 climbed 1.6%. In Europe, London's FTSE 100 rose 1.4%, and Germany's Xetra Dax added 0.6%.

If you liked this article you might like

Paradigm Opportunity Protects Investors in Tough Times

Paradigm Opportunity Protects Investors in Tough Times

5 Things You Need to Know Before the Stock Market Opens (Correct)

5 Things You Need to Know Before the Stock Market Opens (Correct)

U.S. Investors Brace for a Third Bailout in Greece

U.S. Investors Brace for a Third Bailout in Greece

5 Things You Need to Know Before the Stock Market Opens

5 Things You Need to Know Before the Stock Market Opens

40 Hedge Funds' Best Stocks Show the Way for 2012 (Update 1)

40 Hedge Funds' Best Stocks Show the Way for 2012 (Update 1)