Updated from 4:05 p.m. EDT

Stocks ended lower Tuesday, as terrorist attacks in the Middle East and negative analyst comments gave investors a reason to take some money off the table after a two-day rally.

The Dow Jones Industrial Average ended down 47 points at 8679, while the Nasdaq fell almost 2 points to 1539. The S&P 500 shed 3 points to 942. Over the past two days, the Dow had climbed 235 points, or almost 3%, while the Nasdaq had jumped 52 points, or 3.5%.

"I just think we've come a long way and are taking a breather," said Peter Blatchford, trader at Miller Tabak & Co. "We've pretty much shrugged off the events in Saudi Arabia."

Dozens of people were killed, including seven Americans, in explosions at a residential compound that housed Westerners in Riyadh. Secretary of State Colin Powell condemned what he termed terrorist attacks that had "earmarks" of al Qaeda.

"The bombing in Saudi Arabia, the wider trade deficit and the downgrade in the semiconductors gave investors three reasons to take profits off the table," said Peter Cardillo, chief strategist at Global Partners Securities. "But I think we're digesting the news pretty well; it's not as if we're falling off a cliff or anything."

Cardillo said the weaker dollar is now being perceived as a short-term positive, and he noted that the trade deficit revealed a small increase in exports.

Still, some analysts are increasingly concerned about a bigger pullback in the market after recent gains. Bear Stearns analyst Francois Trahan reduced his recommended equity asset allocation to 60% from 65%, and increased his cash weighting to 15% from 10%.

"We continue to believe that 2003 will prove to be a better year for equities, but our valuation model argues that much of the good news to come for stocks is already priced in," he wrote. "Technical indicators of overbought/oversold readings mostly argue for a coming pullback in the stock market."

Trahan set an S&P 500 target of 1,025 for the end of 2004.

The day's economic news also suggested that stocks might have advanced too much recently. The U.S. trade deficit ballooned in March to its second-widest level on record, as a big gain in oil prices pushed oil imports up to a record $9.1 billion. Although imports were up sharply, exports also rose slightly, aided by a weaker dollar.

Donald Straszheim, strategist at Straszheim Global Advisors, said that while it's still possible the market breaks through its October lows, he doesn't believe that's likely to happen.

"When we look at a basket of stocks -- big well-known names, in many industries -- they are far above their recent bottoms, and we doubt they will retrace all of that territory," he said. Still, he did note that sharp run-ups like this are typically followed by a sharp reversal.

In corporate news, Wal-Mart ( WMT) posted a 14% rise in first-quarter net income, in line with estimates of 42 cents per share, and up from 37 cents a share a year earlier. The retailer said a weaker dollar and cost cutting helped the results. Shares fell 2% to $55.49.

J.C. Penney ( JCP) earned $61 million, or 20 cents a share, in the latest quarter, down from $86 million, or 29 cents a share, last year. The latest quarter's earnings topped estimates by 2 cents a share. Shares rose 5% to $18.85.

Merrill Lynch downgraded five chipmakers' stocks to neutral from buy on concerns that demand for their products will falter: ATI Technologies ( ATYT), Intersil ( ISIL), Maxim Integrated ( MXIM), Nvidia ( NVDA) and Semtech ( SMTC). The Philadelphia Semiconductor index fell 0.8% to 355.

Schering-Plough ( SGP) posted sharply lower first-quarter earnings and revenue because of generic competition for the allergy drug Claritin. Net income fell to 12 cents a share from 41 cents in the year-ago period. The company's new CEO also said he was "withdrawing" 2003 earnings guidance as he tries to get a handle on Schering's financial condition. Shares were up 2% at $18.71.

Martha Stewart, the chief executive of Martha Stewart Living ( MSO), is in settlement talks with the Justice Department after prosecutors supposedly ran into difficulties proving allegations of insider trading against her, the Financial Times reported. Shares were up 14% at $10.65.

Qwest ( Q) founder and former Chairman Philip Anschutz will pay $4.4 million to settle charges that he received IPO shares in exchange for his firm's investment banking business, according to New York state attorney general Eliot Spitzer. Qwest was down 1.7% at $4.49.

Avanex ( AVNX) surged 143% to $2.93 after the maker of fiber-optic products agreed to buy Alcatel ( ALA) and Corning's ( GLW) optical-components units for $63.5 million in stock to broaden its line of technologies.

The dollar stemmed its slide against the euro after reaching its lowest level in four years early Monday. But it lost ground against the yen.

Overseas markets were mixed, with London's FTSE 100 up 0.3% at 3999 and Germany's Xetra DAX down 0.9% at 2909. In Asia, Japan's Nikkei closed 0.4% lower at 8190, while Hong Kong's Hang Seng shed 0.4% to 9119.

Treasuries were a touch lower, with the yield on the 10-year note rising to 3.62%. Crude oil prices for June delivery rose following the suicide attack.

Stocks surged Monday, with the Dow gaining 122 points, or 1.4%, to 8726. The S&P 500 rose 11 points, or 1.3%, to 945, its highest level in more than eight months, while the Nasdaq gained 21 points, or 1.4%, to 1541.