The tech-heavy Nasdaq closed at a record for a fourth session in a row Wednesday as the Dow industrials slipped lower as the stunning firing of Federal Bureau of Investigation Director James Comey stoked questions about President Donald Trump’s ability to build enough consensus in Washington to implement market friendly polices.

“This certainly isn’t a positive, something that makes you want to go out and buy stocks, but it is too early to tell how big of a market-moving event this will prove to be,” said Bruce McCain, chief investment strategist at Key Private Bank.

For now, investors seem to be taking a “wait-and-see” approach, he said.

The Nasdaq Composite Index COMP, -1.26% rose 8.56 points, or 0.1%, to close at a record 6,129.14, for its fifth consecutive session of gains.

The Dow Jones Industrial Average DJIA, -0.46% fell 32.67 points, or 0.2%, to finish at 20,943.11, as shares of Walt Disney Co. DIS, -1.41% contributed 17 points to the decline. Losses on the average widened after Boeing Co. BA, +0.04% shares accounted for another 16 points of decline following reports it was halting flights of its 737 MAX jets to inspect engine problems.

The S&P 500 SPX, -0.84% was up 1 point, or less than 0.1%, to 2,398, with eight out of 11 sectors trading higher, led by the energy sector.

With valuations stretched by some metrics, equities could be vulnerable to prolonged uncertainty coming out of Washington, analysts said.

Late Tuesday, Trump said he dismissed Comey over the FBI director’s handling of the investigation into campaign rival Hillary Clinton’s emails. The reaction on Capitol Hill to Comey’s firing has ranged from approval to outrage. In a press conference, Deputy White House press secretary Sarah Huckabee Sanders told reporters that Trump had considered firing Comey since the election.

Read:Complete text of White House statement on firing of FBI’s Comey

And see:At first, Comey reportedly thought his firing was a prank

The political uncertainly offset a strong rally in the energy sector XLE, +0.14% , which gained 1.1% as oil futures US:CLM7 settled up 3.2% at $47.33 a barrel. Crude was higher after an industry group reported a drop in U.S. crude supplies, a positive sign for demand. Among specific names, shares of Chevron Corp. CVX, +0.29% rose 1.4% as the biggest advancing stock on the Dow industrials.

Gold futures US:GCM7 settled up 0.2% at $1,218.90 an ounce

The insurance industry is about to get a whole lot weirder

European stocks SXXP, -0.50% finished higher, while Asian markets largely gained.

In the latest economic data, import prices rose 0.5% in April, while export prices were up 0.2%. Both were higher than expected. The U.S. recorded an April budget surplus of $182 billion, boosted by a change in the corporate tax-filing deadline.

Check out:MarketWatch’s Economic Calendar

Stock movers:Abercrombie & Fitch Co. shares ANF, -0.90% jumped 12% in heavy trading following a Reuters report the retailer was fielding buyout interest.

Mylan NV MYL, +1.00% shares rose 0.8% after the drugmaker posted first-quarter profit that exceeded expectations, though revenue was weak.

Fashion-accessories makerFossil Group Inc. FOSL, -3.84% and online reviews providerYelp Inc. YELP, -5.35% both plummeted following disappointing quarterly results. Shares of Fossil were down 20% while Yelp shed 18%.

Read the First Take: Yelp plummets as advertisers revolt

Online travel broker Priceline Group Inc. US:PCLN lost 4.5% after delivering a weak second-quarter outlook late Tuesday.

Entertainment titan Walt Disney Co. DIS, -1.41% finished down 2.2% after posting earnings that topped forecasts, but revenue that missed views. The stock was the biggest decliner among Dow components.

On the upside, Nvidia Corp. NVDA, -0.40% jumped 18% after the maker of graphics chips topped profit forecasts late Tuesday.

Electronic Arts Inc. EA, -1.16% was up 13% following better-than-expected earnings.

Wendy’s Co. WEN, +0.66% rallied 5.1% after the fast-food chain beat first-quarter profit and sales expectations, and provided an upbeat outlook.

Inc. Research Holdings US:INCR reached a deal to combine with private-equity owned inVentiv Health, creating a large biopharmaceutical outsourcing provider. The agreement values inVentiv at $4.6 billion, including debt. Shares of Inc. gained 21%.

Whole Foods Market Inc. US:WFM shares declined 0.9%, after an earlier rise, following a report that grocery chain was looking to name a new chairman and replace half its board.

Coty Inc. COTY, -0.92% shares jumped 12% after the company said it was looking to overhaul the Cover Girl brand of cosmetics to make it more attractive to retailers.

Shares of News Corp. NWSA, +0.66% NWS, +1.20% , which owns The Wall Street Journal and MarketWatch, declined about 3% following the release of earnings late Tuesday.

—Victor Reklaitis in London contributed to this report.