Stock prices have soared for months in defiance of an ailing, pandemic-wrecked economy. Now they seem impervious to something even more disturbing: the erosion of American democracy.

Last week’s shocking events, when an American president incited a mob to confront lawmakers preparing to certify his electoral defeat, raised alarms about the health of U.S. governing institutions.

But the country’s political decay will need to get a great deal worse before it knocks financial markets off stride, analysts said. That’s good news for investors, but it also means that Wall Street is unlikely to act as a brake on further institutional deterioration.

“The market is agnostic about politics,” said Marc Chandler, chief market strategist for Bannockburn Global Forex. “We like to think democracy is better. But at the end of the day, investors don’t seem to care so much about that.”

Still, if the violence and rebellion worsens, average Americans eventually could pay. The entire economy benefits from the pools of global capital that are invested in U.S. stocks and bonds. If investors lose faith in the U.S. system, the consequences would be felt on Main Street.

“If global investors suddenly develop suspicions about the U.S. political system, that it’s not stable, they will stop buying our debt. So U.S. interest rates will go up. Mortgage rates will go up,” said David Smick, an adviser to hedge funds and investment firms. “When interest rates go up, it’s not good for the stock market. So people’s 401(k)s will go down. … There are a lot of really ugly scenarios that could unfold.”

Unprecedented televised images of rioters attacking police, battering the U.S. Capitol’s doors and windows, and vandalizing lawmakers’ offices staggered foreign officials and executives, said Smick, who last year grew so concerned about the domestic situation that he funded “Stars and Strife,” a documentary film about the growth of political discord.

Last week’s drama was a reminder that the $21 trillion U.S. economy rests on a political foundation — the consent of the governed, rule of law, freedom of speech — that allows individuals to count on a level playing field as they jockey for riches.

All of that seemed under threat last week when an unruly crowd of Trump supporters broke through police barricades and ransacked offices in the Capitol, interrupting lawmakers who were certifying President-elect Joe Biden’s election victory.

“Markets globally look at us and what do they see? Huge political dysfunction,” Smick said. “You can’t believe how stunned they are.”

Yet Smick and other market observers do not expect the democratic unraveling to dent asset prices anytime soon. In this view, the U.S. system, though battered and under threat, is holding.

Trump’s bid to persuade Vice President Pence to exceed his constitutional powers and overturn Biden’s November win failed. Congress formally recognized the Democrat as the next president after dozens of federal judges — including some appointed by Trump — blocked his election challenges. And the media has kept citizens informed of the president’s scheming.

Despite last week’s violence in Washington — and the danger of a repeat performance — both financial and political conditions are near-perfect for stocks, analysts said.

The outcome of the November elections means Biden will have enough support to do things investors like, but not enough to do the things they don’t like.

Democratic control of the Senate, following the party’s sweep of two Senate seats in Georgia, makes it more likely that Biden will be able to get economy-boosting proposals, such as a multitrillion-dollar stimulus, through Congress.

But with the upper chamber split 50-50, Democrats must depend upon Kamala D. Harris as vice president to break any ties, dooming the progressive wish list that Wall Street abhors, such as Medicare-for-all or steep income-tax hikes.

Financial conditions are even more favorable. With the Federal Reserve planning on keeping interest rates near zero for years, business borrowing costs will remain low and stocks will face little competition from bonds for investors’ cash.

Since March 23, the markets’ pandemic low, the Dow Jones industrial average has risen roughly 67 percent. The blue-chip index hit 31,000 for the first time Jan. 7, the day after the Capitol riot.

Stocks’ impressive returns are a reminder that the market measures just one financial metric: companies’ future earnings prospects. Though politicians often speak of markets as if they represent a comprehensive report card on the economy’s health, they don’t.

To be sure, outside events can temporarily jostle investors. But unless they represent a lasting change in the ability of companies to earn money, even the worst development becomes a mere blip on traders’ screens.

Few days were potentially more alarming than Nov. 22, 1963. President John F. Kennedy’s assassination that day horrified Americans and shaved nearly 3 percent off the Dow Jones industrial average.

Yet when trading resumed after the president’s funeral four days later, stocks regained the lost ground in a single trading session before continuing their ascent for an additional 2½ years.

Still, it’s not difficult to conjure up reasons for concern about the current U.S. outlook. The mayor of Washington is urging Americans for their own safety to avoid the Jan. 20 inauguration. The outgoing president just became the first chief executive in the nation’s history to be impeached for a second time. And despite thousands of armed National Guard troops ringing the Capitol, there are fears that the mob may return.

Jan. 6 was more than a protest that got out of hand. Federal prosecutors may charge some of those involved with “sedition and conspiracy,” a felony punishable by up to 20 years in prison, Michael Sherwin, the acting U.S. attorney for the District of Columbia, said this week.

The FBI has warned that right-wing extremists are plotting armed protests in Washington and all 50 state capitals beginning later this week and potentially extending until the inauguration. And polls show a sizable percentage of Republicans reject Biden’s legitimacy, leaving the government to contend with a long-term challenge.

Yet investors are taking the tumult in stride. The Dow remains above the 30,392 level it reached Jan. 5, the day before the abortive insurrection. The U.S. dollar also has gained fractionally against major world currencies since last week.

If investors are sanguine, it may be because the country has weathered plenty of turmoil in its nearly 245-year history.

Over an 18-month period in 1971-1972, for example, the FBI reported an average of more than five domestic bombings by radical groups each day — a total of more than 2,500 explosions, author Bryan Burrough writes in “Days of Rage,” a history of the era’s violent underground movements. Yet stocks climbed by an annual average of 10 percent throughout that period.

A quarter-century later, the country was convulsed by news that President Bill Clinton was having an affair with a young White House staffer. Investors shrugged.

Over 13 months from the initial disclosure to the president’s acquittal on impeachment charges, the Dow rose almost 20 percent.

Democracy is not required for economic growth. For proof that authoritarian economies can grow impressively, look no further than China, which has grown at an annual rate of more than 9 percent for the past 30 years.

Investors also have reaped solid returns from Turkey, despite President Recep Tayyip Erdogan’s strongman rule. The Istanbul index has gained 57 percent since an August 2018 currency crisis.

Some experts who evaluate political risks in developing countries are increasingly scrutinizing the United States. Meredith Wilson, chief executive of Emergent Risk International, which advises corporations and investment firms, began devoting more time to assessing domestic U.S. conditions as corporate executives found it difficult to fathom Trump’s intentions.

Companies feared antagonizing the mercurial president and ending up in the crosshairs of his Twitter account and struggled to keep pace as new policies were announced and revoked without warning.

Even before the attack on Congress, Wilson said she had anticipated rising extremism on both ends of the political spectrum. Now, the combination of the runaway pandemic, which has left many people angry and isolated, and a belief among Trump supporters that the election was stolen has intensified the danger of domestic radicalization.

“We are in for a period of turmoil akin to the late ’90s. It does look pretty scary,” she said, alluding to events such as the 1995 Oklahoma City bombing.

Investor confidence could be tested by more violence between now and Biden’s inauguration, according to Samuel Brannen, director of the risk and foresight group at the Center for Strategic and International Studies.

“I would tell companies they have a lot to worry about between today and January 20th: site security, employees’ security, customers’ concerns,” said Brannen. “After January 20th, they can take a little bit of a breath. … But we’re in a dangerous environment.”