In the last week of the race, Mr. Santos announced that he had begun preliminary talks with a second, smaller guerrilla group, the National Liberation Army, or ELN, offering the prospect of a comprehensive peace that could, if successful, end decades of jungle battles, bomb attacks, kidnappings and political killings. Despite Sunday’s optimistic tone, the talks with FARC have dragged on for more than 18 months.

Mr. Zuluaga and his backers charged that Mr. Santos was willing to give away too much to achieve peace, and they warned that guerrilla leaders could skip jail time or other punishment for their activities.

Mr. Zuluaga, 55, was supported by former President Álvaro Uribe, Mr. Santos’s predecessor and a political powerhouse who retains a strong base of support. Mr. Uribe once backed Mr. Santos, but the two split after Mr. Santos was elected. Mr. Uribe became one of the most vocal critics of Mr. Santos’s efforts to strike a peace deal.

Mr. Santos had warned that Mr. Zuluaga would be a puppet of Mr. Uribe, who was recently elected to a Senate seat.

The campaign was something of a role reversal for Mr. Santos, who had been Mr. Uribe’s defense minister. When he ran four years ago, Mr. Santos was the candidate who vowed to be tough on the guerrillas and to carry on Mr. Uribe’s legacy.

Mr. Santos, who studied at Harvard and the University of Kansas, had seemed likely to cruise to a second term, not least because the economy had grown steadily, including at a rate of 4.3 percent last year.

But he received a scare in the first round of voting last month: Mr. Zuluaga came in first and Mr. Santos ran second in a field of five candidates. Because no one received more than 50 percent of the vote, the election was decided in Sunday’s runoff.