According to exit polls, the sharp-tongued, silver-haired politician known as "AMLO" won by a large margin over his two main rivals, who both conceded defeat shortly after the polls closed -- laying to rest concerns that a deeply divided country could face prolonged uncertainty over the winner.

Thousands of ecstatic supporters flooded central Mexico City's Zocalo square and Alameda park, celebrating to the sounds of mariachi music as Lopez Obrador slowly made his way there from his campaign headquarters in a motorcade, swarmed by huge crowds.

"The government was failing. We needed a real change," said one elated supporter, Jose Gutierrez, 44.

Runner-up Ricardo Anaya of the conservative National Action Party (PAN) and third-place candidate Jose Antonio Meade of the ruling Institutional Revolutionary Party (PRI) both congratulated Lopez Obrador and wished him success.

It is a major shift in Mexican politics: the PRI and PAN have governed for nearly a century, and Lopez Obrador will be the country's first leftist president in recent history when he takes office on December 1.

Three polling firms gave the former Mexico City mayor the win. Newspaper El Financiero's exit poll gave him 49 percent of the vote to 27 percent for Anaya and 18 percent for Meade.

Polling firms Mitofsky and the Strategic Communications Cabinet announced broadly similar results.

Lopez Obrador, 64, successfully tapped voters' anger over a seemingly never-ending series of corruption scandals and horrific violence that left a record 25,000 murders last year -- an orgy of bloodshed fueled by the country's powerful drug cartels.

Casting his ballot early Sunday at his polling station in Mexico City's Tlalpan district, he called the elections "historic." "We represent the possibility of real change," he told hundreds of journalists crowded at the entrance, promising a "peaceful transformation" of the country.

Lopez Obrador's coalition -- led by the Morena party he launched in 2014 -- appeared to be on track for a strong showing in state and congressional races as well, winning six of the day's nine governor's races, according to exit polls.

That included Mexico City, where a woman was elected for the first time ever, the scientist and environmentalist Claudia Sheinbaum.

Two other states were too close to call, according to Mitofsky.

Lopez Obrador's coalition will have a majority in the lower house, and possibly in the Senate as well, according to the firm's exit polls -- a coup for a party contesting its first national elections.

After a campaign of lofty but vague promises, the new president will now face a big challenge to deliver, said political analyst Jose Antonio Crespo.

"He'll have Congress's support and a great deal of legitimacy, but things don't change magically," he told AFP.

In a country awash in violence, the campaign has been the most blood-stained in Mexican history: 145 politicians have been murdered since September, according to consulting firm Etellekt.

Three political party members were shot dead on election day, according to local officials: a Workers' Party (PT) member in the western state of Michoacan, and two members of the ruling Institutional Revolutionary Party (PRI) in the central state of Puebla.

Most of the murders have been of local politicians, the most frequent targets for drug cartels seeking corrupt officials they can strike alliances with.

But Mexicans are deeply divided over Lopez Obrador, who was making his third presidential bid.

He has clashed with Mexico's business community, with some critics warning he would pursue Venezuela-style socialist policies that could wreck Latin America's second-largest economy.

Seeking to soothe, he has recruited a team of market-friendly advisers and backpedaled on his most controversial proposals, including reversing outgoing President Enrique Pena Nieto's landmark energy reform, which privatized the oil sector.

The country's Business Coordinating Council, one of its largest business groups, appeared ready to call a truce.

"We will work with the president-elect's team to build an agenda for stability, trust and development," its director, Juan Pablo Castanon, told a press conference.

The Mexican peso was stable on international currency markets.

Lopez Obrador will face a laundry list of challenges, including a lackluster economy and a thorny relationship with the United States under President Donald Trump, whose anti-trade, anti-immigration policies have turned diplomacy with Mexico's key trading partner into a minefield.

"AMLO" has vowed to put Trump "in his place." But the US president appeared ready to start off on the right foot.

"I look very much forward to working with him," he tweeted. "There is much to be done that will benefit both the United States and Mexico!"

Catch the biggest newsmakers and the biggest newsbreaks on CNN-News18, the only news destination. Keep watching CNN-News18 at just 50 paise per month. Contact your cable/DTH operator now!