W HEN BRAZILIAN soldiers invaded Paraguay in 1865, after banding together with Argentina and Uruguay, the country lost a quarter of its territory and perhaps 90% of its male population. A century later Brazil sent soldiers to a disputed border region and withdrew only after the two countries agreed to build the world’s largest hydro-electric dam.

The dam, named Itaipu, is still a sore subject in Paraguay. Last month it emerged that in May Paraguay’s current president, Mario Abdo Benítez, had struck a secret deal with Brazil, further reducing Paraguay’s access to cheap power. The resulting outcry has put Mr Abdo Benítez at risk of impeachment. The fiasco has underlined the importance of renegotiating the dam’s governing treaty, which expires in 2023.

Under the current agreement, which was signed in 1973, each country has the right to half the dam’s output. Paraguay, a country of 7m people with little industry, only uses about a quarter of its share, which fulfils 90% of its electricity needs. It sells the rest to Brazil, which depends on the dam for 15% of its power. But Paraguay is paid only the cost of production (including debt repayments for construction), not the market price of electricity. According to the calculations of Miguel Carter of DEMOS , a think-tank, had Brazil been made to pay full whack, between 1985 and 2018 it would have paid $75.4bn more, or roughly twice Paraguay’s current annual GDP .

In 2009 Brazil’s then-president, Luiz Inácio Lula da Silva, agreed to triple Brazil’s annual payment and to take steps to allow Paraguay’s state power company, ANDE , to sell directly to private Brazilian companies. But in May’s secret deal, a clause that would have made Brazilian companies bid for power was struck out. Paraguay also agreed to receive around 18% less money over the next three years.

The agreement became public in July, when the head of ANDE , Pedro Ferreira, refused to sign it, resigned and accused Mr Abdo Benítez of “high treason”. He and Paraguay’s minister of foreign relations—who also resigned, along with three other officials—told prosecutors that a “parallel negotiation” was under way to sell power exclusively to a Brazilian energy company, Léros. A politician from the party of Brazil’s president, Jair Bolsonaro, travelled to Paraguay three times on behalf of Léros.

Mr Ferreira gave text messages to the Paraguayan press purporting to show that an adviser to Paraguay’s vice-president, Hugo Velázquez, acting with the knowledge of Mr Abdo Benítez, was arranging meetings with Léros and lobbying on its behalf. In the messages, the adviser, José Rodríguez, claims that the Brazilian politician, Alexandre Giordano, represents not only Léros, but also Mr Bolsonaro’s family and the Brazilian government. The vice-president now denies employing Mr Rodríguez, though he admitted to meeting him to discuss the possibility of Léros buying energy from Paraguay. Mr Ferreira has a different story: he says the vice-president personally introduced Mr Rodríguez as his legal adviser. In one of the text messages, Mr Velázquez asks Mr Ferreira how negotiations for the sale are going. News of the secret deal prompted thousands of people to take to the streets, calling for Mr Abdo Benítez to be impeached. On August 1st Mr Bolsonaro agreed to scrap the agreement. Proceedings in Paraguay’s congress, which had the support of some of the president’s allies, were then dropped. But it is too late to stop the outcry about energy policy. In 2023 the $2bn loan taken out to build the dam will at last be paid off. The question is what to do then. “People on the streets are already talking about the renegotiation [of the deal],” says Mercedes Canese, a former vice-minister from Frente Guasú, an opposition party. Many in Paraguay argue that the country should use the excess power itself to industrialise. Drawn by low taxes as well as cheap electricity, car companies have started manufacturing cables in Paraguay to export to Brazil. In Ciudad del Este, just south of the dam, many locals engage in Bitcoin mining, an exceptionally power-hungry business. Demand from homes and offices is growing quickly, too. Within a few decades, Paraguay’s half of Itaipu’s output “will go to air-conditioning”, says Christine Folch, the author of “Hydropolitics”, a forthcoming book about the dam.

At that point, the country will need new energy sources. Until then, however, most of the power will still be sold to Brazil. Brazil’s economy is 50 times bigger than that of its landlocked neighbour. And Paraguay’s negotiating position is weak. Whereas Mr Bolsonaro put a trio of generals in charge of the Brazilian half of Itaipu, Paraguay does not even have a fully fledged energy ministry. The messages published by Mr Ferreira show how Brazil sets the agenda.

Public pressure may help change that. On August 7th Paraguay’s government appointed Geraldo Blanco, an engineering professor with a plan to use more of Itaipu’s electricity in Paraguay, to the dam’s governing council. As it contemplates its strategy for 2023, Paraguay may look to other smaller countries’ battles with big neighbours. In the 1970s a campaign involving the actor John Wayne helped persuade America to pass a law that returned Panama’s canal in 1999. As for the businesses best suited to provide the investment needed for Paraguay’s industrialisation, they are right over the border in Brazil. ■