WHEN HE ran successfully for president of Guatemala two years ago, Jimmy Morales was a political novice, best known as a television comedian playing feeble-minded peasants. It turns out Mr. Morales, now caught up in a corruption probe and constitutional crisis of his own making, is just as dim-witted as the characters he once portrayed.

Faced with a spiraling inquiry into allegations that his campaign received more than $800,000 in anonymous, unreported contributions, and could not explain how it covered major expenditures, Mr. Morales decided to take aim at his primary accuser. Bad move.

The target of the president’s pique is Iván Velásquez, a deeply respected Colombian lawyer who heads the United Nations’ anti-corruption commission in Guatemala. A uniquely powerful agency that works with local prosecutors, the decade-old commission, under Mr. Velásquez’s direction since 2013, has uncovered a staggering number of systemic scandals. They included a mammoth customs fraud and bribery plot that toppled Mr. Morales’s predecessor, Otto Pérez Molina, who is now in jail facing trial.

As Mr. Velásquez and his team of international investigators closed in on the campaign finance scandal last week, the president hightailed it to New York, seeking relief from U.N. Secretary General António Guterres. Failing to get it, on Sunday Mr. Morales ordered Mr. Velásquez expelled from Guatemala for exceeding his authority.

Mr. Morales’s expulsion order was not just artless; it was political suicide. Denounced by the United States and its Western European allies, the order was promptly reversed by Guatemala’s highest court. The health minister and other top officials resigned in protest. In New York, Mr. Guterres pronounced himself “shocked.” In the capital, Guatemalans took to the streets to protest. Now the country’s attorney general has asked the Supreme Court to revoke the president’s immunity from prosecution.

One of Latin America’s most graft-steeped countries, Guatemala is notorious for corruption and judicial impotence, and its politicians and officials have long enjoyed impunity. Political campaigns are bankrolled by government contractors. Murder is rarely prosecuted. Accountability barely exists in the public arena. It is no secret that Guatemala’s broader ills, including an extreme case of income inequality, cannot be addressed by an ongoing pattern of kleptocratic governance working in league with organized crime and drug-trafficking networks.

Mr. Velásquez, known as “Ivan the Feared,” has done more than anyone to attack those problems systematically and promote the rule of law. For that — and for protecting judges and prosecutors, establishing a witness protection program and utilizing modern investigative techniques — he and the commission are widely revered.

Mr. Morales, whose party was backed by right-wing military officers implicated in Guatemala’s murderous, decades-long civil war, won election pledging to fight “the corruption that has consumed us.” Now it seems likely to consume him. If the country’s Supreme Court and Congress agree to strip him of official immunity, his days in office, and possibly as a free man, may be numbered. With more pushing by Mr. Velásquez, so may Guatemala’s systemic corruption.