Investors embraced the election of Donald Trump as president, snapping up stocks and selling bonds in a bet that the Republican’s plans for fiscal stimulus will succeed in breaking the U.S. out of a postcrisis economic funk.

The Dow Jones Industrial Average posted its second large gain this week, rising 256.95 points to 18589.69, led by a rally in financial, pharmaceutical and engineering firms. Meanwhile, the yield on the 10-year U.S. Treasury note surged to 2.07%, its highest level since January. Yields rise when prices fall.

The action shows that after months of either playing down the likelihood of a Trump presidency or selling shares in a defensive reflex when Mr. Trump rose in pre-election polls, investors are welcoming the prospect that expansive fiscal spending under the Trump administration could bolster economic activity, push up inflation and support higher bond yields in coming years.

Markets React to Vote

A Trump stimulus could be good for stocks and bad for bonds, analysts said, by boosting economic growth that would bolster hiring and corporate earnings while cutting taxes, leading to deepening deficits that tend to be associated with higher interest rates.

Mr. Trump’s election also sent waves through industries deemed likely by investors to be sharply affected by potential changes in government policy.

The Republican’s victory throws doubt on AT&T Inc.’s proposed acquisition of Time Warner Inc. Mr. Trump said in October that he would block the AT&T-Time Warner deal, and that he would try to break up the Comcast Corp. -NBC Universal merger. In both cases, Mr. Trump said the media is controlled by too few people. Shares of AT&T rose 1.2%, while Time Warner shares, which were already trading at a wide discount to AT&T’s offer, fell 1.5%.

At an investor conference Wednesday, AT&T finance chief John Stephens extended an olive branch. “We really look forward to working with President-elect Trump,” Mr. Stephens said. “His policies and his discussions about infrastructure investment, economic development and American innovation all fit right in with AT&T’s goals.”

Drugmakers and some other firms have been hit hard this year by fears that Democratic nominee Hillary Clinton would have favored measures to sharply limit drug-price increases. Mr. Trump’s election should free up a sector that some view as deeply undervalued, said some analysts and investors.

“The case for health-care stocks is clear cut,” said Eddie Perkin, chief equity investment officer at Eaton Vance. “It has been the worst-performing sector in the S&P 500 year to date, and the removal of political risk is a near certainty.”

While Mr. Trump’s election could temporarily trip up the surging mergers-and-acquisitions market, it may ultimately spark an acceleration in deal making, bankers and lawyers said. Some deal makers said they view a Trump victory as a long-term positive. The Obama administration has stepped up scrutiny of mergers and a number of proposed deals have fallen apart in the face of antitrust and other regulatory pressure.

Investors were shocked by Donald Trump's presidential win. Now they are assessing the future. WSJ City Editor Phillipa Leighton-Jones speaks to Rebecca Byrne about the market reaction.

Some investors said they weren’t sure how seriously to take the prospect of Trump stimulus, saying he has committed only verbally and hasn’t released detailed plans or outlined relative priorities. At the same time, many said they believe Mr. Trump views his mandate as centering on restoring U.S. growth after a tepid postcrisis economic expansion that ranks among the slowest ever.

Many investors saw evidence Wednesday that the market is already grappling with likely nuances. Mr. Trump has promised to spend $1 trillion on infrastructure projects, a position that was applauded by Caterpillar Inc., which also relies heavily on export markets. Caterpillar shares rose 7.7% Wednesday.

“We’ve got a lot to do at home on building our own infrastructure in this country, and we are excited about some of the things that he has said in this regard,” said Kathryn Dickey Karol, Caterpillar’s vice president for global government and corporate affairs.

But Martin Richenhagen, chief executive of farm-equipment maker AGCO Corp. , said he is concerned about Mr. Trump’s repeated support for trade protectionism. “That would be a nightmare if we make life difficult for imports and exports,” said Mr. Richenhagen, who was in Germany this week. AGCO shares rose 0.5%.

While his election stands to provide relief to drugmakers worried about the specter of government price limits, it likely will fan fears for hospital operators and some health insurers that the Medicaid expansion in President Barack Obama’s health law could get rolled back. That provision had brought those companies more paying customers.

Mr. Trump has vowed to repeal the Affordable Care Act, though many analysts think it is unlikely that all of the ACA’s effects would be undone. Mr. Trump also took aim at high drug prices during his campaign, hinting at measures such as reimportation of drugs and giving Medicare powers to negotiate drug prices to limit price rises.

J. Mario Molina, CEO of Molina Healthcare Inc., a large insurer of Medicaid patients, expects the new administration to expand Medicaid further. “Health-care reform is in place, it’s going to be modified, it’s going to move forward,” he said. Molina shares dropped 16% Wednesday and HCA Holdings Inc., the biggest U.S. hospital company, saw its shares drop 11%.

Wednesday’s rally came after Mr. Trump’s surprise victory spiraled through financial markets overnight Tuesday and into Wednesday morning, sending U.S. stock futures and the dollar sliding and havens such as gold and the Japanese yen soaring.

Jonathan Corpina, senior managing partner at Meridian Equity Partners, said he arrived at the New York Stock Exchange at 7:15 a.m. and—after following a tumultuous night of stock-futures trading—was surprised to see indications that the market could open flat or higher.

As Mrs. Clinton walked to the podium to give her concession speech at about 11:30 a.m. Eastern time, Mr. Corpina said a hush fell over the NYSE trading floor. He said traders crowded around televisions on the floor and turned up the volume. As Mrs. Clinton delivered remarks, which underscored a smooth transfer of power, the quiet on the floor was punctuated by phone rings and computer beeps announcing client orders.

“She kept her head high, she said the right things, and that helped with the overall market,” Mr. Corpina said.

The yield on the 10-year Treasury note fell as low as 1.720%, according to Tradeweb, but then climbed above 2% for its biggest one-day yield gain since 2013.

Donald Trump's Victory: Impact on Business

The decline in bond prices extends a selloff that began this summer after yields in the developed world hit record lows after the U.K.’s vote to leave the European Union.

Some investors said Wednesday’s moves reflect more the manic state of the markets than the impact of potential infrastructure spending, which both candidates had proposed during the campaign.

“We just priced in too much stimulus too quickly for my liking,” said David Rosenberg, chief economist and strategist at Gluskin Sheff & Associates.

—Riva Gold, Dana Mattioli and Ryan Knutson contributed to this article.

An image of President-elect Donald Trump appears on a television screen on the floor of the New York Stock Exchange on Wednesday. Photo: Associated Press

Write to Aaron Kuriloff at aaron.kuriloff@wsj.com and Corrie Driebusch at corrie.driebusch@wsj.com