(CNN) -- A Brazilian court has ordered an immediate halt to construction of a controversial hydroelectric dam project in the Amazon.
It's the latest twist in a long-brewing battle between the Brazilian government and local indigenous communities over the Belo Monte dam.
The government has backed the construction of what would be the world's third-largest hydroelectric dam, while activists argue that it would displace thousands of local residents and damage the environment.
In the most recent ruling, announced by Regional Federal Judge Souza Prudente to reporters, construction is ordered suspended until indigenous communities get a say on the matter before congress, court spokesman Jair Cardoso said.
Injunctions blocking construction have been issued in the past, but the government has successfully overturned them.
Congress approved the Belo Monte dam in 2005 and construction started in 2010 when then-President Luiz Inacio Lula da Silva signed a $17 billion contract with Norte Energia, the consortium chosen to build the dam.
But lawmakers erred in not seeking input from the indigenous communities beforehand, the judge ruled.
"The legislation requires consultation (by indigenous communities) prior to a decision by congress (on construction of the dam), and what we have is an attempt after the fact," Prudente told the state-run Agencia Brasil news agency. "Congress made a mockery and acted as if it were in a dictatorship, putting the cart before the horse."
Norte Energia had not received notification of the ruling as of Wednesday, and would not comment for the time being, spokeswoman Sarah Barros said.
The company will be fined $250,000 daily if it does not comply.
If and when it is completed, Belo Monte will be the third-largest dam in the world, after the Three Gorges dam in China and the Itaipu dam on the Brazil/Paraguay border.
The dam, being built on the Xingu River, a tributary of the Amazon, will produce 11,000 megawatts and provide electricity for 23 million homes.
According to Norte Energia, after environmental considerations the area to be flooded by the dam was reduced to 516 sq. km (200 sq. miles). Estimates of the number of people who will be displaced by the construction of the dam range from 19,000 to 40,000.
The judge also found fault with a previous regional federal court decision that assumed that the country's supreme court had upheld the constitutionality of the legislation behind the dam construction, according to Agencia Brasil. The decision in question had been the opinion of a single judge. For matters of constitutionality, two-thirds of the high court judges would have to agree.