LIMA, Peru — One Peruvian ex-president shot himself dead as the police arrived at his door. The head of the opposition sits in jail, under investigation herself. And for about a day this week, the president and vice president both claimed to rightfully lead Peru.

Long an anchor of stability in Latin America, Peru looked close to ungovernable.

The turmoil that has roiled the country for more than a year was on full display this week, as a clash between the current president, Martín Vizcarra, and the opposition ended with the president dissolving Congress. The opposition-led legislature had none of it, calling the vote illegal and swearing in the vice president to take over as confused Peruvians looked on.

Peru would seem an unlikely candidate for the kind of upheaval it has faced in recent years. It has been at peace since 2000, when a civil war with the Shining Path, a Maoist guerrilla group, that claimed about 69,000 lives over two decades drew to an end. That same year, President Alberto Fujimori resigned, ending eight years of dictatorship.

The democratic transition coincided with a boom in the economy, fueled by high commodity prices overseas, a growing mining sector and an expanding middle class of consumers. And while the growth has slowed, to 4 percent last year, Peru still remained a head above its neighbors in Latin America.