You’ve no doubt seen the disturbing images coming out of Peru. Violent protesters have set fire to government buildings, forced airports to close down, kidnapped police officers, attacked media offices, looted shops, invaded factories, and blocked highways and access routes to food distribution centers. At least seven people have been killed and hundreds injured.

The United States, European Union and United Kingdom have expressed support for Dina Boluarte, Peru’s first female president, and called for an end to the pandemonium. Ms. Boluarte has declared a state of emergency, but it is unclear whether this will suffice to contain the well-organized violence.

Ms. Boluarte, the former vice president, assumed office after Pedro Castillo, her predecessor, was impeached by the Peruvian Congress and removed from office following an attempted “self-coup” earlier this month that would have turned Peru into a dictatorship. He has now been detained and is under investigation.

Contrary to the narrative being peddled by Peru’s extreme left, with help from the populist-left governments of Mexico, Colombia, Argentina and Bolivia, Mr. Castillo is no victim. Mr. Castillo attempted to destroy Peru’s democratic institutions by dissolving the Congress and judiciary and governing by decree. He ordered the arrest of prosecutors who were investigating him. And his call for a constituent assembly to rewrite the constitution had one purpose and one purpose only: to increase his power while reducing that of anyone who might challenge him.

All of the measures were illegal, reminiscent of Peru’s tragic past, when a sequence of coups and self-coups prevented the rule of law from taking root. Luckily for Peru, this most recent attempt failed.

A former teachers union official close to MOVADEF—a front for Shining Path, the Maoist terrorist organization—Mr. Castillo ran for the presidency in 2021 as the candidate of the misnamed Free Peru party, another Marxist-Leninist group.

His campaign revolved around a pledge to rewrite the constitution. Though he very narrowly won, his promise to redo the constitution instilled fear in millions of Peruvians, and not just those who supported his opponent, Keiko Fujimori, daughter of another ex-president.

The fear was justified because other Latin American countries have followed the same path, in which extreme left populists gain power through legitimate electoral means and then dismantle the country’s democratic political institutions and legal system and concentrate permanent power in their own hands.

Under current law, Peru’s constitution can be reformed only by Congress, where Mr. Castillo and his allies did not gain a majority. Once in power, he sought ways around this impediment, while Vladimir Cerron, head of the Free Peru party, was busy placing his pawns in key positions across the country.

During his 1½-year rule, Mr. Castillo was implicated in more corruption scandals than many of his corrupt predecessors accumulated in five years. But he managed to avoid impeachment, in part because he bribed several members of Congress.

Then Peru’s attorney general filed corruption charges against him, a first for a sitting president, and his popularity plummeted. Earlier this month he decided to stage his coup, expecting support from the armed forces. He miscalculated. The military and the police refused to comply, leading to his arrest.

The courts have determined that he remain in preventive custody while he is investigated.

The crisis has sparked violent actions by extremists, particularly in the south, with Latin American autocrats and would-be autocrats, including the four previously mentioned governments, as well as Venezuela and Cuba, stoking the fires from abroad.

It’s clear from speaking with my many contacts throughout the region that the Latin left has suffered a major setback in a pivotal South American country—and they know it. Their response has been to blatantly interfere in Peru’s affairs on the side of a corrupt would-be dictator.

This is crunch time for Peru’s liberal democracy, now a key battle scene in Latin America. If the authoritarian populists achieve their goal, they will have gained a major ally; if they do not, Peru’s surviving democracy might inspire a tidal wave of anti-populist movements keen on reversing a dangerous trend that has placed the region on the path to dictatorship and economic misery.