The Supreme Court dismissed a challenge by Museveni’s opponents, who had appealed against a ruling by the constitutional court that removed an age cap of 75 for presidential contenders.
“This appeal therefore fails,” Chief Justice Bart Katureebe declared in handing down the court’s majority 4-3 verdict.
In December 2017, a bill was signed to abolish age limits for presidential candidates, allowing Museveni — who has ruled since 1986 — to seek re-election in polls due in 2021.
That decision sparked protests and an outcry from the opposition, which accused the president of seeking to rule for life.
The constitutional court upheld the amendment in a ruling in July last year.
In January, the Supreme Court began hearing an appeal by opposition petitioners who unsuccessfully argued the earlier ruling was unconstitutional.
Museveni once said leaders who “overstayed” were the root of Africa’s problems.
However, while running for a fifth term in 2016, he said it was not the right time for him to leave, as he still had work to do.
In February, the ruling party endorsed Museveni as its candidate for 2021.
He is the only president most Ugandans have known in a country where the median age is less than 16.
Download our app and read this and other great stories on the move. Available for Android and iOS.