MEXICANS went to the polls in almost half the country’s states on July 7th for a round of local elections. All eyes were on Baja California, the only state to be electing a new governor. In a close race, President Enrique Peña Nieto’s Institutional Revolutionary Party (PRI) looked to be in with a chance of snatching control of the state from the National Action Party (PAN), which has held it for 24 years. Preliminary results suggest that in the end the PAN managed to cling on to power. So why might Mr Peña be breathing a sigh of relief that his PRI candidate lost the race? When his presidency began on December 1st, Mr Peña unveiled the “Pacto por Mexico”, an agreement between the three main parties to pass a broad package of reforms for which the country had been crying out for years. The effect of the Pacto has been dramatic: in contrast to the legislative logjam seen during much of the past decade, Mr Peña’s government has pushed through a slew of important new laws. The past six months have seen an education reform, an anti-monopolies law to attack the fiefs of Carlos Slim and Televisa, and a legal reform to free up the courts. Many more are planned.

Yet the Pacto is at risk. Some members of the two main opposition parties, the conservative PAN and the left-wing Party of the Democratic Revolution (PRD), are beginning to wonder if it’s such a good idea to vote for all the president’s initiatives. Though the Pacto contains policies that all parties broadly agree on, its success is making the president and the PRI rather popular. Meanwhile, internal rivalries are tearing the PAN apart, and the PRD is facing a crisis after Andrés Manuel López Obrador, its presidential candidate last year, announced that he would establish a new, rival left-wing party. As the July 7th elections approached, some members of the opposition began to argue that, if the results were bad, they should withdraw from the Pacto, and pursue a more obstructive line against the president.

Mr Peña might therefore be relieved that preliminary results suggest that his party’s candidate lost the battle of Baja California. Winning a single state, and in return risking the Pacto, could have been quite a Pyrrhic victory. That’s not to say that the Pacto is safe. For one thing, a recount under way in Baja California may yet change the result. Secondly, with the elections out of the way the government is about to pursue its most controversial reforms yet, to allow more private investment in the energy sector and to raise taxes. With Mr López Obrador preparing street demonstrations against these initiatives, it will be more tempting than ever for the main leftist opposition party to bail out of the Pacto. Although the battle of Baja California appears to have been successfully fought and lost, Mexico’s president faces a long, politically heated summer.