Wall Street extended a recent rally on Monday but finished the session short of earlier highs after several people were killed by a truck driven into a Christmas market in Germany.
All three major U.S. indexes ended higher but lost some steam after German police said a truck ran into a crowded Christmas market in Berlin, killing nine people and injuring up to 50 others.
That rattled U.S. investors already eyeing potential global troubles after the Russian ambassador to Turkey was shot dead in Ankara.
"Markets want to be sure whether this is an isolated incident. Will this disrupt economic activity in just this area or will it be a wider area and for how long?," said John Canally, chief economic strategist for LPL Financial. "That's the playbook by which markets have come to address these types of issues."
The S&P technology index .SPLRCT rose 0.61 percent, with Microsoft, Intel, Apple and Amazon.com lifting the Nasdaq Composite to within a hair of last Tuesday's record high close.
U.S. stocks have been on a tear since the Nov. 8 presidential election, with the S&P rising nearly 6 percent on bets that President-elect Donald Trump's plans for deregulation and infrastructure spending will boost the economy.
The Dow Jones industrial average is less than 1 percent away from 20,000, a level it has never breached.
"The Trump rally is still with us. Every time something's down for two days, people jump on it. People are looking for buying opportunities," said Jake Dollarhide, chief executive officer of Longbow Asset Management in Tulsa, Oklahoma.
However, some investors warn that uncertainty around Trump's policies and the uncertainty of whether they are approved by Congress pose major risks to current stock prices.
The Dow Jones industrial average .DJI rose 39.65 points or 0.20 percent to end at 19,883.06.
The S&P 500 .SPX ended up 0.20 percent at 2,262.53 after trading as high as 2,167.47.
The Nasdaq Composite .IXIC added 0.37 percent to end at 5,457.44.
Microsoft (MSFT.O) rose 2.12 percent, Amazon.com (AMZN.O) gained 1.09 percent, Intel climbed 1.60 percent and Apple (AAPL.O) climbed 0.58 percent. All four provided the biggest boost to the Nasdaq and the S&P 500.
United Technologies (UTX.N) rose 2.12 percent, helping lift the Dow, after Credit Suisse upgraded the stock to "outperform" and increased its price target.
Walt Disney (DIS.N) rose 1.34 percent after its "Rogue One: A Star Wars Story" movie scored the second-largest December opening in history.
Advancing issues outnumbered declining ones on the NYSE by a 1.66-to-1 ratio; on Nasdaq, a 1.34-to-1 ratio favored advancers.
The S&P 500 posted 13 new 52-week highs and no new lows; the Nasdaq Composite recorded 157 new highs and 38 new lows.
About 6.1 billion shares changed hands in U.S. exchanges, well below the 7.5 billion daily average over the last 20 sessions.
(Additional reporting by Tanya Agrawal in Bengaluru and Rodrigo Campos in New York; Editing by James Dalgleish)