Jose Raul Mulino left his farm and horses behind with his sights set on becoming Panama's vice president under his former boss, ex-head of state Ricardo Martinelli.
Then, in March, Martinelli was disqualified from contesting the presidency -- a month after he lost his final legal bid to avoid prison time for money laundering and took asylum at the Nicaraguan embassy.
Mulino, 64, stepped into his shoes and rode his mentor's popularity to the finish line -- winning elections Sunday with more than a third of votes cast in the single-round, first-past-the-post national election.
His mere participation, however, was touch and go.
Mulino's candidacy was challenged in court on the basis that he had not participated in a primary vote or picked a running mate, as required by law.
The Central American country's Supreme Court finally approved his run just two days before election day -- swayed, it said, by the right of Panamanians "to elect and be elected."
Under Martinelli -- who was president from 2009 to 2014 -- Mulino had served as justice minister and public security minister.
He had been held in preventive detention for alleged corruption in 2015-2016, but was released due to procedural errors.
He claimed to have been a "political prisoner."
Mulino replaced his erstwhile boss as the candidate of the right-wing Realizing Goals party using the slogan: "Mulino is Martinelli."
A recent poll showed most Panamanians believe that with Mulino in charge, it will actually be Martinelli calling the shots from behind the scenes.
Mulino has dismissed the criminal conviction of his former boss as politically motivated, and will now be in a position to pardon him.
On the campaign trail, Mulino had promised to close the dangerous migration route through the Darien jungle between Colombia and Panama.
More than half a million undocumented migrants passed through the so-called Darien Gap last year -- while being subjected to abuses criticized by rights groups.
Mulino's other pledges included building a railroad from the capital to his native Chiriqui region near the border with Costa Rica, and to reform the country's battered pension system.
He would also build a pet hospital to be called "Bruno," after Martinelli's beloved dog, which accompanied him into asylum.
Mulino is a maritime law expert by training.
In the 1980s, he was part of the so-called Civic Crusade, a movement against military dictator Manuel Antonio Noriega who was unseated when the United States invaded the country in 1989.
After the invasion, Mulino served briefly as foreign minister in the democratically-elected government of president Guillermo Endara.
Mulino is described as confrontational and is said to have an authoritarian leadership style.
As security minister, he once called protesters who disrupted traffic "scum."
He did not take part in any presidential debate, confident that Martinelli's lasting appeal with voters would carry him over the finish line.
Many Panamanians credit Martinelli with an economic heyday fueled by an infrastructure boom that included the enlargement of the Panama Canal and construction of Central America's first metro line.
"The vote for Martinelli is why I'm here," Mulino said recently.
The president-elect is married to pet store owner Maricel Cohen.
He describes his passion as spending time on the farm his wife gave him when he turned 50, among the chickens, rabbits and other animals.