MEXICO CITY/NEW YORK - Mexico's peso and Brazil's real are among the best performing currencies globally against the dollar this year, but their performance could diverge as political and economic risks cloud their outlook, analysts said.

Since the start of the year, the Mexican currency has strengthened 2.3% against the dollar while the real has appreciated 6.8%. That is no mean feat against a dollar up almost 19% versus a basket of peers this year and scaling levels last seen two decades ago.

The contrast is also stark with regional peers such as Colombia's peso, down 17% under the weight of political uncertainty.

So far, the strength of the Mexican and Brazilian currencies is tied to fundamentals, with healthy current account balances and rate differentials enticing traders and investors.

"What makes those Latin American currencies attractive in a way that East Asia is not, is that the two big themes this year seem to be commodities and rates - and both Brazil and Mexico have been fairly aggressive (in hiking)" said Marc Chandler, chief global strategist at Bannockburn Global Forex in New York.

With the Mexican benchmark rate at a record 9.25% and Brazil's at 13.75%, both offer some of the highest differentials to even the Fed's estimated 4.6% peak rate sometime next year. With inflation expected at 5.8% by year-end, Brazil's positive real rates near 9% are among the highest in the world.

But electoral volatility could take away some of the currency's shine as Brazilians head to a runoff between former president Lula da Silva and incumbent Jair Bolsonaro on Oct. 30, with markets more bullish on a Bolsonaro win, said Dirk Willer, head of emerging market strategy at Citi Research in New York.

"If Lula wins by a big enough margin that there's no uncertainty about the results, it's not terrible for the currency. It is the currency with the highest real yields anywhere," Willer said.

"You don't want to see a contested election, but I'm not sure if Lula wins that gives you significant downside," he said, adding that a move by Lula to appoint an orthodox finance minister would help keep volatility at bay.

For Mexico, however, an imminent return of capital to the United States caused by the Fed ramping up rates could weigh on the peso, alongside expectations of a U.S. slowdown.

"By the beginning of 2023 at the latest, the depreciation of the Mexican peso will have to come," said Alfredo Coutiño, head of Latin America Economic Research at Moody's Analytics, who estimates the correction could be in the area of 20%, spread though late 2022 and 2023 and even into 2024.

Such a move would take the peso to near 2020 lows of around 25 per dollar from the current level of just over 20.

"It seems to me that next year, as the Fed continues to increase rates, the Bank of Mexico could even say 'We are staying here' and I think that factor may affect (the peso)," said Carlos González, head of analysis at Monex Grupo Financiero.

This year's outperformance was underpinned by steady inflows of remittances, hitting an all-time high in July as well as strong export growth and foreign direct investment inflows, analysts said.

A 60% chance of a recession in the U.S., Mexico's largest trading partner by a long shot, could reverse all of this.

(Reporting by Rodrigo Campos in New York and Noe Torres in Mexico City; Editing by Hugh Lawson)