A court in Ecuador has upheld a ruling that prevents the government from selling land in the Amazon rainforest to oil companies, a move activists called a historic win for the Waorani indigenous tribe living there.

The government had appealed an earlier court ruling in April that the 2,000-strong tribe had not been properly consulted over plans to auction their ancestral lands to oil companies.

The decision late on Thursday from Pastaza province in the eastern Amazon to uphold the ruling ends the years-long legal battle over the land, campaigners said.