Supporters of Mr. Nasralla’s alliance celebrated early Monday, filling the small plaza outside the hotel in Tegucigalpa, the capital, where the tribunal had set up operations for the vote.
Although Mr. Hernández has succeeded in reducing some of the murderous violence besieging Honduras, and he has promoted social programs, his likely election loss reflected how polarizing he has become.
How he managed to get his name on the ballot may prove to be what damaged his candidacy the most. The Honduran Constitution includes an ironclad ban on presidential re-election, a prohibition so unshakable that it was cited as the reason for ousting President Manuel Zelaya in a 2009 coup.
Back then, Mr. Zelaya was believed to be angling for a way to get around the ban, although his left-wing policies may have been the real reason the country’s political and business elites wanted him out of Honduras.
If Mr. Nasralla becomes president, Mr. Zelaya will return firmly to the center of Honduras’s political scene.
As the founder of Libre, the main party in the alliance, Mr. Zelaya campaigned with Mr. Nasralla and was widely seen as the alliance’s main strategist. The alliance platform was drawn up with contributions from Libre supporters, including ministers and economists who had worked in Mr. Zelaya’s government.
Although Mr. Hernández tried during the campaign to portray the alliance as a far-left group allied with Venezuela, at least some voters may have handed their votes to Mr. Nasralla because they were nostalgic for Mr. Zelaya, who raised the minimum wage sharply.
Mr. Nasralla, who did not enter politics until 2011 and speaks on the stump with the cadences of the game-show host he once was, has benefited from the perception that he is an outsider who is not corrupt.
Mr. Hernández gambled that voters would be willing to hand him more power in exchange for increased security. When he took office in 2013, drug and gang violence made Honduras the deadliest country in the world outside a war zone. With tens of millions of dollars a year in aid from the United States, Mr. Hernández dismantled several drug cartels and extradited a dozen traffickers to the United States.
He also set up special investigative units in the police and the attorney general’s office and improved street policing in some of the worst neighborhoods.
Thousands of corrupt or inefficient police officers were fired and replaced by newly trained ones. It is unclear if the top commanders believed to have been working for drug cartels will face prosecution.
The overall homicide rate fell 28 percent through 2016 and has continued to decline, although Tegucigalpa and the country’s industrial capital, San Pedro Sula, remain among the world’s most murderous cities.
But Mr. Hernández has been tainted by evidence of corruption in the National Party. Frustration with corruption spilled onto the streets in 2015, when Hondurans marched in torchlit demonstrations for weeks.
The movement forced Mr. Hernández to accept an outside panel of foreign prosecutors to work alongside Hondurans in the attorney general’s office to prepare anticorruption cases.
The fate of that panel would be unclear under Mr. Nasralla’s presidency.
The government would be unlikely to roll back measures that have worked to reduce violence, although Mr. Nasralla has raised questions about some elements of the police purge. The alliance’s platform also criticizes what it calls the “servile” relationship with the United States.
Mr. Nasralla would also face demands to increase economic growth and create jobs in one of Latin America’s poorest and most unequal countries. Almost two-thirds of Hondurans live in poverty and struggle for access to health care and other services.