MEXICO CITY (Reuters) -Mexico's presidential candidates formally ended their campaigns on Wednesday, with most polls showing ruling party hopeful Claudia Sheinbaum on course to become the country's first woman president after Sunday's national vote.

Latin America's No. 2 economy will hold its largest election ever, with more than 20,000 local, state and federal government positions up for grabs and almost 100 million Mexicans eligible to vote.

In the previous presidential context in 2018, 63% of eligible voters cast ballots, and pollsters point to hard-to-predict turnout as a key variable for this election.

In addition to the presidency, voters will pick lawmakers for both chambers of Congress, a new mayor of Mexico City, eight state governors, as well as scores of local officials.

Sheinbaum, a former Mexico City mayor, closed her campaign in the capital's bustling Zocalo square on Wednesday afternoon alongside her party's mayoral hopeful for Mexico City, Clara Brugada.

Brugada is vying to maintain the left's hold on power in the sprawling metropolis, which leftists have controlled since voters began electing its mayor in the late 1990s.

Sheinbaum, a 61-year-old scientist, vowed to build upon the legacy of current President Andres Manuel Lopez Obrador, her close ally who in 2000 tapped her to be his environment chief when he was mayor of the capital.

"The foundations have been laid," Sheinbaum said, praising Lopez Obrador for his efforts to reduce poverty and violence.

The frontrunner has spoken of adjusting policy around key issues including energy, security and corruption, but has avoided highlighting differences with Lopez Obrador.

Sheinbaum pledges to be the one who will govern if she wins, but some say her political mentor would loom large.

Meanwhile, Xochitl Galvez, the standard bearer of a left-right opposition coalition, closed her campaign in Monterrey, a city in Mexico's northern industrial heartland, days after she led a massive rally in the capital.

The 61-year-old former senator and businesswoman has promised to improve and expand social programs as well as fight corruption and the widespread violence unleashed by organized crime, in a country where homicides have reached a record 185,000 in Lopez Obrador's term.

"Enough with the lies! They say Mexico is better than ever, and it's not true ... Mexico wants peace and tranquility," Galvez said at her event in the town of Los Reyes Acaquilpan, in the State of Mexico.

Later on Wednesday, the violence of the current campaign season was punctuated by the point-blank assassination of a local mayoral candidate belonging to the same coalition backing Galvez in southern Guerrero state.

The gunning down of the mayoral hopeful at a campaign event was captured on video and marks the 36th murder of a candidate during the 2024 cycle, equaling the previous record of assassinations from midterm elections three years ago, according to data from security consultancy Integralia.

Galvez trails Sheinbaum by 17 points in the Oraculus poll-of-polls, an average compiled by local polling firm Buendia & Marquez.

Whoever wins will face challenges on multiple fronts, including rampant impunity amid high murder rates and kidnappings, meager economic growth and questions over future energy policy.

Jorge Alvarez Maynez, a 38-year-old former lawmaker who trails far behind in third place, will close his campaign with a concert in Mexico City.

(Reporting by Ana Isabel Martinez; Additional Reporting by Diego Ore, Lizbeth Diaz and Valentine Hilaire; Editing by Daniel Wallis and Stephen Coates)

By Ana Isabel Martinez