GUATEMALA CITY (Reuters) - Conservative Alejandro Giammattei swept aside his center-left rival in Guatemala’s presidential election on Sunday, and now inherits an unpopular migration deal agreed under duress with the Trump administration that could severely test his country.

With preliminary results from over 95% of the polling stations counted, the electoral tribunal declared Giammattei the winner with almost 59% of the vote, ahead of his center-left rival, former first lady Sandra Torres, back on 41%.

“It will be an immense honor to be president of this country that I love so much,” Giammattei said to a crowd of cheering supporters at a news conference in Guatemala City. “We will rebuild Guatemala. I have no words to say how grateful I am.”

The next president takes office in January. By then Guatemala may be bogged down in the accord reached at the behest of U.S. President Donald Trump which aims to turn the troubled Central American country into a buffer zone to stem migration.

Yielding to the threat of a raft of economic sanctions from Trump, outgoing Guatemalan President Jimmy Morales agreed to make his country a so-called safe third country for migrants, despite its high levels of poverty and violence.

Giammattei, a trained surgeon and veteran public sector bureaucrat who had failed in three previous bids to secure the presidency, has called the accord “bad news,” saying Guatemala is not ready to cope with a potential jump in asylum-seekers.

Many Guatemalans agree with him.

Slideshow ( 22 images )

“I think it’s the most ridiculous thing this president could have done, because if Guatemala is mired in poverty, how is it going to take in migrants if we don’t have anything to eat ourselves?” said Mercedes Escoto, 65, a retired teacher and Giammattei supporter as she voted in Guatemala City.

A poll published this week by Guatemalan newspaper Prensa Libre showed more than eight out of 10 respondents rejected the idea of the country accepting foreign migrants seeking asylum.

It is unclear how much Giammattei will be able to do to change the deal, which would require Hondurans and Salvadorans to apply for asylum in Guatemala rather than the United States. It also foresees granting U.S. visas to some Guatemalan workers.

Risa Grais-Targow, Latin America director at consultancy Eurasia Group, said while the accord struck with Trump risks a popular backlash, not honoring it could expose Guatemala to U.S. taxes on remittances or tariffs on its goods.

“The next president faces a lose-lose situation when it comes to managing the deal with the United States,” she said. “That is the biggest challenge the incoming president faces.”

Giammattei will also take on a country struggling with a 60% poverty rate, plus widespread crime and unemployment, which have led hundreds of thousands of people to migrate north.

Slideshow ( 22 images )

The 63-year-old has promised to erect an “investment wall” on the border between Guatemala and Mexico to curb migration, and also proposed bringing back the death penalty.

Many Guatemalans are fed up with the political class after investigations by the International Commission against Impunity in Guatemala (CICIG), a U.N.-backed anti-corruption body, led to the arrest of then-President Otto Perez in 2015, then threatened to unseat his successor Morales, a former TV comedian.

Morales narrowly escaped impeachment, and the CICIG also went after Torres for suspected campaign finance irregularities. As a candidate, she was immune from prosecution.

Both candidates vowed to fight corruption - albeit without “foreign interference,” an apparent nod to the CICIG.

Giammattei pledged to run an honest government as he voted.

“We’ll battle corruption from the very first day,” he said.

Morales, who ordered the termination of the CICIG’s mandate as of September, was barred by law from standing again.