A conservative former prisons director was elected Guatemala’s president on Sunday, in a race that took place against the backdrop of a migration crisis in which thousands of Guatemalans leave the country each month.

Alejandro Giammattei, 63, who was making his fourth run for the presidency, won nearly three-fifths of the vote in beating Sandra Torres, the former first lady, according to preliminary results from Guatemala’s election board.

Neither candidate inspired much confidence and just over 42 percent of eligible voters cast ballots.

That so many Guatemalans choose the uncertainty of migration over the poverty, violence and corruption they know at home is a sign of the challenges facing Mr. Giammattei, who has little political experience.