President Evo Morales of Bolivia, who came to power more than a decade ago as part of a leftist wave sweeping Latin America, resigned on Sunday after unrelenting protests by an infuriated population that accused him of undermining democracy to extend his rule.
Mr. Morales and his vice president, Álvaro García Linera, who also resigned, said in a national address that they were stepping down in an effort to stop the bloodshed that has spread across the country in recent weeks. But they admitted no wrongdoing and instead insisted that they were victims of a coup.
“The coup has been consummated,” Mr. García said.
Mr. Morales was once widely popular, and stayed in the presidency longer than any other current head of state in Latin America. He was the first Indigenous president in a country that had been led by a tiny elite of European descent for centuries, and he shepherded Bolivia through an era of economic growth and shrinking inequality, winning support from Bolivians who saw him as their first true representative in the capital.
“I want to tell you, brothers and sisters, that the fight does not end here,” Mr. Morales said on Sunday. “The poor, the social movements, will continue in this fight for equality and peace.”
“It hurts a lot,” he added.
Mr. Morales’s reluctance to give up power — first bending the country’s laws to stand for a fourth election, then insisting that he won despite widespread concerns about fraud — left him besieged by protests, abandoned by allies and unable to count on the police and the armed forces, which sided with the protesters and demanded he resign.
As the country slipped into deeper turmoil over the weekend, protesters voiced their fear of Bolivia’s trajectory under Mr. Morales.
“This is not Cuba. This is not Venezuela!” they chanted in La Paz, Bolivia’s main city, over the weekend. “This is Bolivia, and Bolivia will be respected.”
Carlos Mesa, the former president who came second in last month’s election, celebrated Mr. Morales’s resignation, which he characterized as “the end of tyranny.”
It remained unclear on Sunday night who would take power, as several officials in the line of succession had resigned. Mr. Morales’s resignation statement was expected to be read in Congress Monday.
Mexico’s foreign minister, Marcelo Ebrard, said on Twitter on Sunday night that his country would offer Mr. Morales asylum if he sought it. Late Sunday night, Mr. Morales said in a statement on Twitter that the police were seeking to arrest him “illegally” and that “violent groups” had assaulted his home.
Mr. Morales’s departure is a milestone in the spasms of unrest that have roiled Latin America in recent months. Several leaders in the region have been bedeviled by street protests, acts of vandalism and deepening political polarization — dynamics exacerbated by underperforming economies and rising outrage over inequality.
As it became clear that the military would turn on him, Mr. Morales flew with Mr. García and a small number of aides from La Paz to Chimoré, in the state of Cochabamba. It was unclear whether Mr. Morales intended to leave Bolivia or stay in that area, which is home to coca leaf growers and has been a stronghold of support.
Mr. Morales’s increasing grip on the country had been worrying critics — and many supporters — for years.
In 2016, he had asked voters to do away with the two-term limit established in the 2009 Constitution, which was drafted and approved during his first term. Voters narrowly rejected the proposal in a referendum — which, under Bolivian law, was supposed to have been binding.
But Mr. Morales found a workaround. The Constitutional Court, which is packed with his loyalists, held that term limits constricted human rights, giving Mr. Morales the right to run for office indefinitely.
The beginning of the end for Mr. Morales came on Friday night, when a smattering of small police units made dramatic pronouncements that they were breaking from the government and joining protesters angry over suspicions that the Oct. 20 presidential election had been rigged.
Mr. Morales appeared intent on weathering the storm until his generals abandoned him on Sunday. During his presidency, Mr. Morales went to great lengths to make the armed forces an integral part of his political movement, mindful of the country’s long history of coups.
Christoph Harig, a research fellow at University of the Federal Armed Forces Hamburg, Germany, who studies the relationship between the military and civilian leaders in Latin America, said Mr. Morales’s ouster did not constitute an “old-school coup in which the military aims to take power itself.”
But he said the sequence of events that led to the president’s resignation was “not the sign of a healthy democracy,” and added to the recent events in Latin America in which military leaders have been dragged into political disputes.
“It once more reinforces the military’s position as final arbiter in political crises,” he said, predicting that it would “further fuel polarization.”
Police officers in La Paz were among the first to join the revolt. Initially, many took to the streets with bandannas or surgical masks covering their faces, apparently fearful of being identified. But as their ranks grew, many shed the masks and used bullhorns to address protesters.
“Our duty will always be the defense of the people,” a female officer said through tears in a televised address. “The police are with the people!”
By Sunday, the rebellion had spread to the military.
Shortly before Mr. Morales went on national television to announce his resignation, the commander of Bolivia’s armed forces, Gen. Williams Kaliman, said the military chiefs believed he should step down to restore “peace and stability and for the good of our Bolivia.”
When Bolivians went to the polls in October, many expressed hope that the president would suffer the first electoral loss since his landslide victory in 2005. Graffiti denouncing Mr. Morales as a “dictator” was ubiquitous in the capital.
The opposition felt victorious when initial results showed that Mr. Morales had failed to carve out the 10-percentage-point margin needed for an outright win and would have to face a runoff. That scenario was potentially ruinous for Mr. Morales because other opposition candidates had endorsed the runner-up, Mr. Mesa.
Without explaining why, election officials stopped releasing information on the vote count for 24 hours. The evening after the election, they announced a stunning update: Mr. Morales had won outright, with enough votes to avoid a second round.
Opposition leaders and international observers cried foul, saying that Mr. Morales’s turn of fortune defied credulity. Angry mobs attacked election buildings around the country, setting some on fire.
In subsequent days, large demonstrations and strikes paralyzed much of the country. Mr. Morales defended his electoral triumph as rightful and called on supporters to take to the streets in a show of force. Many have, including bands that have roughed up people protesting the government.
Mr. Morales’s standing grew precarious on Sunday after the Organization of American States, which monitored the election, issued a preliminary report that outlined irregularities and said the vote should be annulled.
In response, Mr. Morales called for a new election in an extraordinary concession. But it did not appease demonstrators and opposition leaders, who renewed calls for him to step down.
The president’s hold on power grew more tenuous as the day wore on. Leading figures in his party resigned, and the military launched operations that appeared intended to protect protesters from armed bands of Morales supporters.
Mr. Morales, a member of the Aymara Indigenous people, rose to prominence as a union leader for coca leaf growers. On his watch, the country’s power structure was transformed. Women today hold nearly half the seats in Congress, and Indigenous people hold more sway than ever.
His first term also coincided with a commodities boom that allowed him and other leftist leaders in Latin America to lift millions out of poverty through subsidies and political patronage. One of the poorest nations in the world, Bolivia used proceeds from natural gas exports to turbocharge its economy.
His party, the Movement for Socialism, has long been the country’s dominant political force, controlling both houses of Congress. Opponents struggled to compete with Mr. Morales because of his enormous support, but they also faced enormous personal risk. Mr. Morales has unleashed allies in the judiciary against political rivals, many of whom have landed in jail or gone into exile.
Raúl L. Madrid, a professor of government and Latin American politics at the University of Texas at Austin who studies Bolivia closely, said Mr. Morales came to feel indispensable.
“I think he views himself as the savior of Bolivia, as a representative of the marginalized people of Bolivia, especially Indigenous people,” he said.
Mr. Madrid said that if Mr. Morales had stepped down after his second or third term, he would have walked away with a commendable legacy. Yet, he added, the president’s decision to try to remain in power was unsurprising.
“From the beginning, he was not interested in grooming a successor that could have threatened him from within,” Mr. Madrid said. “These populist leaders who try to hold on to power at all cost end up undermining their legacy, and people remember them as dictators or would-be dictators.”
Leftist leaders in Latin America, including President Nicolás Maduro of Venezuela, Argentina’s incoming president, Alberto Fernández, and former President Luiz Inácio Lula da Silva of Brazil condemned Mr. Morales’s ouster as a coup.
“It’s unfortunate that Latin America has a financial elite that does not know how to abide by democracy and the social inclusion of the poorest people,” Mr. da Silva said.
Jair Bolsonaro, Brazil’s far-right president, said he was pleased to see Mr. Morales go.
“The word coup is used a lot when the left loses,” he told the newspaper O Globo. “When they win, it’s legitimate. When they lose it’s a coup.”
Ernesto Londoño reported from Rio de Janeiro. Cesar Del Castillo and Mónica Machicao contributed reporting from La Paz, Bolivia, and Anatoly Kurmanaev from Caracas, Venezuela.