As Gary Cohn flees the White House, financial markets are discovering that elections have more than one consequence.

President Donald Trump thrilled investors by delivering the combination of tax cuts and deregulation that has helped push stock prices higher during his 14 months in office. But he is also delivering two things that threaten to bring the economic party to an end.

One is a poorly managed, scandal-ridden administration. Special counsel Robert Mueller's investigation poses an existential threat to the Trump presidency, but lesser hazards corrode its day-to-day operations.

Trump's first national security advisor pleaded guilty to a felony after getting fired; his second, H.R. McMaster, is estranged from his boss and is rumored to be leaving soon. Trump's staff secretary, Rob Porter, was forced to quit over published allegations of domestic violence that the White House had tolerated.

His first Health and Human Services secretary, Tom Price, resigned over his use of taxpayer-funded private jets. Housing Secretary Ben Carson, after the revelation that he had ordered $31,000 worth of taxpayer-funded dining room furniture, was forced to rescind it. The president himself is collecting money from the Republican National Committee for office space in Trump Tower.

Routine dysfunction has defied White House chief of staff John Kelly's efforts to impose order. As Cohn joins Trump confidante Hope Hicks in the extraordinary rush for the White House exit door, the administration has failed to fill even half of the top jobs requiring Senate confirmation.

Internal chaos produced the abrupt, haphazard announcement of Trump's tariff plan that rattled markets last week. And that underscores the second big danger facing investors: a decisive turn toward protectionism that provokes a trade war and tips the economy into recession.

Steel and aluminum tariffs alone won't do that. Retaliation by U.S. trading partners may be limited. Any mainstream replacement for Cohn as Trump's economic advisor will share his opposition to provoking or escalating trade disputes.

Yet Trump may not have exhausted his longstanding impulse for truculent nationalism.

Recent Republican presidents, on core economic questions, have sided with the GOP's pro-business wing over its blue-collar voting base. On taxes and regulation, so has Trump. But he responds to political trouble by drawing closer to his dwindling base, and intense support from blue-collar white voters delivered him the Republican nomination and the presidency.

Trump has recently embraced a sharp reduction in legal immigration despite strong opposition from corporate America. He announced his tariffs decision in the run-up to next week's special House election in southwest Pennsylvania. He plans a last-minute campaign visit this weekend to save a GOP district Trump won by 20 percentage points in 2016.

More significantly, Trump will soon decide how to handle a major pending trade case involving China's abuse of intellectual property rights. The administration pegs the cost to the U.S. of Beijing's transgressions at hundreds of billions of dollars. If Trump chooses to hit China hard, and China responds aggressively, the risk of a wider, economically damaging trade war would sharply escalate.

Paradoxically, Wall Street can take some comfort on trade from Trump's freewheeling operating style. He has few fixed beliefs and a fleeting attention span, rendering any action he takes subject to reversal when he encounters resistance.

He has made clear that he considers stock prices a real-time report card on his presidency. The reaction of financial markets — in either shrugging off Cohn's departure or plunging in fear — will exert its own influence of what Trump does next.