MEXICO CITY — If the candidate was nervous about his chances, few could tell.

Ricardo Anaya was 21 years old and running for elected office for the first time. The prize was a congressional seat in the Mexican state of Querétaro, representing a poor, rural area far from his home in the state capital where he had grown up on a country club. It was enemy territory: His party had never won the seat, and this time would be no different.

But until the final vote tally was announced, the candidate betrayed no sense, beyond his inner circle of confidants, that he might lose.

“He was giving everyone confidence that he could win,” said Jacob Morado García, who was then the local president of Mr. Anaya’s party, the center-right National Action Party, or PAN, in the municipality of Pinal de Amoles. “He did everything possible to win.”

Eighteen years later, Mr. Anaya now finds himself in a somewhat similar position, though the stakes are many orders of magnitude higher.