Bolivia's Constitutional Court has allowed President Evo Morales to run for a fourth consecutive term in 2019.
The court has annulled the result of a referendum held last year, in which a majority of Bolivians rejected his proposal to change the constitution.
It said Mr Morales had lost the vote by a narrow margin because of an illegal defamatory campaign.
The opposition said the ruling was an attack on democracy. Mr Morales has been in office since 2006.
If Mr Morales, 58, wins the next election, his term will end in 2025.
By then, he will have been in power for 19 years.
His supporters say he needs more time in order to consolidate his programme of social reforms.
The opposition says the result of the February 2016 referendum must be respected.
The constitution had already been changed once, lifting restrictions on Mr Morales seeking a third consecutive term in office.
'No means no'
Earlier this month, thousands of people took part in a demonstration in La Paz organised by indigenous groups and the various unions that back Mr Morales' Movement Towards Socialism (MAS) party.
Many said Mr Morales, who is Bolivia's first indigenous leader, should have the right to remain in power for as long as the people voted him in.
The government says it narrowly lost last year's referendum because of a smear campaign against Mr Morales.
Allegations surfaced shortly before the referendum accusing Mr Morales of using his influence to favour a Chinese construction firm in Bolivia, which he denied.
Mr Morales initially said he would respect the outcome of the poll.
But he later appealed to the Constitutional Court.
Mr Morales' defence has quoted the American Convention of Human Rights, saying that the Bolivian people have the right to vote for him and that he has the right to be elected.