By Caroline Valetkevitch
NEW YORK (Reuters) - U.S. stocks ended higher on Wednesday, but the day's uneven path showed investors' sensitivity to any signs of turmoil in the Middle East, with stocks rising on comments by President Donald Trump and paring gains on reports of blasts in Baghdad.
Trump spoke at a White House briefing after Iran's missile strikes overnight on military bases housing U.S. troops in Iraq. The U.S. president said the strikes had not harmed any Americans and that Tehran appeared to be standing down.
Comments earlier from Iran's foreign minister that the country did not seek an escalation and a tweet from Trump that "All is well!" also helped calm investor jitters.
Both the S&P 500 and Nasdaq hit record intraday highs, but major indexes cut their gains late in the day following reports of two blasts heard in Baghdad. After the bell, Iraq's military said two rockets had fallen inside Baghdad's Green Zone but there were no casualties.
"The measured tones coming out of the Trump administration potentially dialing back from a tit-for-tat reaction on balance is positive, but the market is going to react to minute-by-minute news of increased tensions in the Middle East," said Chris Zaccarelli, chief investment officer at Independent Advisor Alliance in Charlotte, North Carolina.
The Nasdaq registered a record high close and most S&P 500 sectors rose, while the S&P 500 energy index <.SPNY> fell 1.7% as oil prices slumped.
Global markets have been rattled by concerns about rising tensions in the Middle East after the U.S. killing of influential Iranian Major General Qassem Soleimani on Jan. 3.
The Dow Jones Industrial Average <.DJI> rose 161.41 points, or 0.56%, to 28,745.09, the S&P 500 <.SPX> gained 15.87 points, or 0.49%, to 3,253.05, and the Nasdaq Composite <.IXIC> added 60.66 points, or 0.67%, to 9,129.24.
Among the day's decliners, Boeing <BA.N> fell 1.8% after a 737-800 jet made by the company and belonging to a Ukrainian airline burst into flames shortly after takeoff from Tehran, killing all 176 people aboard.
Walgreens Boots Alliance Inc <WBA.O> slid 5.8% after its quarterly profit missed expectations. Shares in rival CVS Health <CVS.N> fell 1.3%.
On the upside, Lennar Corp <LEN.N> ended up 0.8% after the No. 2 U.S. homebuilder beat quarterly profit estimates and forecast 2020 homes sales above analysts' estimates as lower home prices and mortgage rates drive demand.
Adding to the upbeat mood, the ADP National Employment Report showed private payrolls jumped by 202,000 jobs last month, well above the 160,000 rise expected by economists polled by Reuters.
Advancing issues outnumbered declining ones on the NYSE by a 1.51-to-1 ratio
The S&P 500 posted 6258 new 52-week highs and no new lows; the Nasdaq Composite recorded 118106 new highs and 149 new lows.
Volume on U.S. exchanges was 7.78 billion shares, compared to the 7.01 billion average for the full session over the last 20 trading days.
(Reporting by Caroline Valetkevitch in New York; Additional reporting by Sinead Carew in New York and Sruthi Shankar and Susan Mathew in Bengaluru; Editing by Jonathan Oatis and Leslie Adler)