TOLUCA, Mexico (Reuters) - Mexico’s ruling party fended off a leftist challenger in a major state election seen as a test run for a presidential vote next year, propelling the country’s peso currency to its strongest level since U.S. President Donald Trump was elected.

Alfredo del Mazo, Institutional Revolutionary Party (PRI) candidate for the Governor of the State of Mexico gestures with team members during the election day in Toluca, Mexico June 4, 2017. REUTERS/Carlos Jasso

But the Institutional Revolutionary Party’s (PRI) 3 percentage-point margin of victory in the central State of Mexico, the country’s most populous, was a close call for President Enrique Pena Nieto, whose party has ruled it for nearly nine decades.

A narrow defeat will not end, or even dampen, the aspirations of leftists led by veteran Andres Manuel Lopez Obrador, an early favorite for next year’s presidential race as the contender of the National Regeneration Movement (MORENA) party. His young party accused the PRI of vote buying and other dirty tricks, and may launch legal challenges in the weeks to come.

With nearly 98 percent of returns in from polling booths, PRI candidate Alfredo del Mazo had 34 percent of the vote compared with 31 percent for MORENA candidate Delfina Gomez.

“We are going to challenge (the results) at many booths where illegal returns were sent, and we believe that with this we could reverse the outcome,” said MORENA secretary general Yeidckol Polevnsky.

In other statewide elections, also held on Sunday, the PRI lost in the western state of Nayarit and narrowly won in Coahuila, which borders the United States.

“The PRI struggled to hold on to the gubernatorial seat in both the State of Mexico and Coahuila, which have traditionally been very favorable electoral battlegrounds, and suffered significant losses in Nayarit and in the municipal election in Veracruz,” said Goldman Sachs economist Alberto Ramos.

“This does not bode well for the PRI in the presidential election next year,” Ramos added.

Still, markets reacted positively to the news that the PRI was bound to retain power in Mexico State.

The Mexican peso gained nearly 2 percent in Monday morning trade, on the setback for Lopez Obrador, a sign of ongoing market distrust of the combative leader who has opposed economic liberalization in Mexico.

The result also gave a boost to OHL Mexico, the Mexican unit of Spanish construction firm OHL, whose share price rose by as much as 9.5 percent.

Slideshow ( 4 images )

Investors fear that Lopez Obrador and other opposition leaders, who have accused OHL Mexico of helping to finance the PRI in the State of Mexico, could go after the firm’s lucrative contracts if they are elected to power. OHL Mexico has rejected the allegations.

HISTORY OF CHALLENGING RESULTS

The PRI is battling widespread anger at corruption and rising violent crime under Pena Nieto as the countdown starts for the July 2018 presidential election.

Lopez Obrador has alleged fraud in past elections, and he vowed to scrutinize the results from every voting booth.

“We will never resort to violence, but we are going to firmly defend this country’s democracy,” he said in a video message. Gomez, the candidate, said she would not protest the result on the streets.

Known as AMLO, the silver-haired politician earned the ire of many Mexico City residents after the 2006 presidential vote when he brought parts of the capital to a standstill with mass protests, saying he had been robbed of victory by center-right candidate Felipe Calderon.

“The lengths that Andres Manuel Lopez Obrador goes to challenge the result will have an important bearing on his presidential candidacy,” said Nicholas Watson of Teneo Intelligence.

Prosecutors are probing the circumstances of piles of pig heads dumped on Saturday near MORENA offices and at polling stations in several municipalities.

Also under investigation were telephone threats and fake electoral literature warning of attacks - tactics used to dissuade people from voting.

Encompassing many populous neighborhoods on the edge of Mexico City, the State of Mexico is home to one in eight Mexican voters and it has long been a source of strength and financing for the PRI.

Del Mazo, however, had a poor showing compared to his predecessors despite his family’s dominance in the state’s politics. He secured barely half the share of vote and a fraction of the margin of victory that the current governor won six years ago with the backing of Pena Nieto, himself a former governor of the state whose own popularity has since plunged.

CORRUPTION, VIOLENCE WEIGH ON PRI

Failing to put a stop to corruption scandals and struggling to tame brutal gang violence has cost the party dearly.

Mexico’s attorney general’s office said on Sunday a former state governor for the PRI, Roberto Borge, had been arrested at Mexico’s request in Panama on corruption charges. Borge, an ex-governor of Quintana Roo, encompassing the resort of Cancun, has previously denied wrongdoing.

Lopez Obrador’s State of Mexico campaign was hurt by a failure to ally with others in the opposition and references by rivals to crisis-hit Venezuela, which the PRI argues mirrors his economic model. He denies the accusation.

The campaigner has opposed the opening of Mexico’s energy sector to private capital, a key reform under Pena Nieto, but no longer vows to reverse it.

Linking Lopez Obrador to late Venezuelan leader Hugo Chavez has helped rivals beat him to the top job in two previous bids at the presidency.

Victory for Lopez Obrador in 2018 could push Mexico in a more nationalist direction at a time of tension with the United States, with U.S. President Donald Trump riling Mexicans with threats to tear up the North American Free Trade Agreement and build a border wall.