U.S. stocks closed higher Wednesday with the Dow industrials and S&P 500 notching new records, shaking off early weakness in the health-care sector to extend gains.

The Dow Jones Industrial Average DJIA, -1.92% marked its third consecutive record close, surging 297.84, or 1.6%, to finish at 19,549.62, following a fresh intraday record. Gains in Nike Inc. NKE, +8.76% , Home Depot Inc. HD, -2.47% and Visa Inc. V, -2.58% outweighed a slump in health-care shares of Johnson & Johnson Inc. JNJ, +0.15% , Pfizer Inc. PFE, -0.69% and Merck & Co. MRK, -0.37%

The S&P 500 index SPX, -2.37% , which also reached an intraday trading high, closed at a record of 2,241.35, a gain of 29.12 points, or 1.3%, with all sectors except the health care—which finished down 0.8%—closing for a gain.

The Nasdaq Composite Index COMP, -3.01% which had been trading in negative territory earlier, turned higher, and finished up 60.76 points, or 1.1%, at 5,393.76, a few points shy of its record close set in late November.

Meanwhile, the Russell 2000 index RUT, -3.04% , a gauge of shares of small-capitalization companies, closed at a record of 1,364.50, after a gain of 11.84 points, or 0.9%. The index has climbed more than 13% since the U.S. presidential election.

Highlighting how markets were broadly climbing, the Dow Jones Transportation Average DJT, -1.06% also closed at a record of 9,371.61, after logging its first record intraday high in more than two years.

Health-care names tumbled early Wednesday after President-elect Donald Trump threatened to cut drug prices. “I’m going to bring down drug prices,” Trump told Time in his “Person of the Year” cover story. “I don’t like what has happened with drug prices.”

The iShares Nasdaq Biotechnology ETF IBB, -1.26% , the most widely used way to place bets on the biotech space, sank 3%.

The stock market’s postelection ascent has been underpinned by hopes that Trump will follow through with a slate of pro-business policies, including boosting infrastructure spending and cutting taxes for the wealthy.

Frank Cappelleri, executive director at Instinet LLC, said investors caught flat-footed by the sustained rally following Trump’s unexpected Election Day win are still rotating into stocks.

“Investors may see a few days of a pause as a reason to get back involved,” said Cappelleri. He said the second reason why this move can extend higher is because investors betting on a downturn “are a little gun-shy” after getting burned in November.

Other strategists say the market has traded in a relatively narrow range since 2014 and make the case that the Trump rally has only lasted a month and has a shot at moving higher into the end of the year.

“It has only been about four weeks since the breakout for stocks and a lot of people are looking at this to be quickly aborted, but the market shouldn’t be faulted for expecting more,” said Bruce Bittles, chief investment strategist at brokerage firm Robert W. Baird & Co.

Another factor that may be supporting stock gains is the belief that traditional selling patterns that occur at the end of the year aren’t being followed because investors are making bets on lower taxes under a Trump administration.

“Anyone who has gained [in December] are not going to want to sell their stocks and pay taxes in April 2017, when they can wait till 2018,” Bittles said. Of course, taxes on profits from the sale of assets could be higher then, but Bittles says Wall Street thinks that it makes more sense to wait and see, which is reducing traditional selling of stocks to take year-end profits and encouraging buying.

“It appears that nothing can stop the equity rally,” said Naeem Aslam, chief market analyst at ThinkMarkets UK, in a note.

However, some strategists and traders are concerned that a pullback might be in the offing because the market has climbed too fast and too furiously.

Indeed, the CBOE Volatility Index VIX, +6.40% is trading at just under 12, which implies that investors may be getting complacent. “Buying volatility at these levels may not be that much of a bad idea,” Aslam said.

Read:Why the rally by U.S. stocks is ‘just getting started’—in one chart

Other markets:European stocks SXXP, +0.55% finished higher, with banks and miners among the session’s big winners, and Asian markets closed broadly higher. Oil futures CLF27, settled down 2.3% at $49.77 a barrel, while gold futures US:GCZ6 advanced 0.6% to settle at $1,177.50 an ounce while a key dollar index DXY, +0.07% slipped 0.3%.

Individual stocks: Ahead of the opening bell, Brown-Forman Corp. BF.A, -0.78% reported quarterly sales that topped estimates, as the maker of Jack Daniel’s whiskey backed its full-year forecast. Shares closed down 0.9%.

Handbag seller Vera Bradley Inc. VRA, -2.80% cut its full-year outlook after missing its own guidance range for the third quarter. Shares tumbled 13%.

Western Digital Corp. WDC, +6.71% shares jumped to close 8.3% higher after the computer hardware maker raised its outlook late Tuesday.

Micron Technology Inc. MU, +0.30% shares rallied 7.3% after Citigroup rated the stock a buy.

Shares of Under Armour Inc. CH:UAA UA, +4.93% surged after the athletic apparel company changed its stock tickers. Class A shares closed up 4.3%, and Class C shares rose 6.4%.

Economic news:Consumer credit in October rose $16 billion, but that was at the slowest pace since June.

The JOLTS report, or Job Openings and Labor Turnover Survey, showed that job openings were unchanged at 5.5 million in October, according to Labor Department.

Investors also are bracing for the European Central Bank’s policy-setting meeting on Thursday. The Federal Reserve entered the so-called blackout period Tuesday ahead of its meeting Dec. 13-14, so there are no Fed speakers on the docket.

Check out:MarketWatch’s Economic Calendar

—Victor Reklaitis in London contributed to this article.