President Andres Manuel Lopez Obrador on Sunday signed into law controversial judicial reforms making Mexico the world's only country to elect all its judges by popular vote.
The outgoing leftist championed the constitutional changes that he says are needed to clean up a "rotten" judiciary serving the interests of the political and economic elite.
Critics fear that elected judges could be swayed by politics and vulnerable to pressure from powerful drug cartels that regularly use bribery and intimidation to influence officials.
Lopez Obrador signed the decree in a video posted on social media, calling it a "historic day."
He was accompanied by president-elect Claudia Sheinbaum, his close ally, who will replace him on October 1 following a landslide election win that left the ruling coalition with large majorities in both chambers of Congress.
"We need justice for everyone, for there to be no corruption in the judiciary, for judges, magistrates and justices to apply to the letter the principle that there is nothing outside the law and no one above the law," Lopez Obrador said.
"It was said that we lived in a democracy, but no, an oligarchy dominated -- they were the ones in charge, those at the top, a minority with a facade of democracy," he added.
Lopez Obrador has frequently lashed out at the judiciary since taking office in 2018 -- in particular the Supreme Court, which has impeded some of his policies in areas such as energy and security.
The judicial reforms have sparked diplomatic tensions with key trade partners the United States and Canada, upset investors and triggered opposition street protests.
Last week, legislators were forced to suspend their debate and move to another location after demonstrators stormed the Senate.
Opponents say the reforms -- under which even Supreme Court and other high-level judges will have to stand for election in 2025 or 2027 -- undermine democratic checks and balances.
Mass election of all judges "does not exist in any other country," Margaret Satterthwaite, UN special rapporteur on the independence of judges and lawyers, told AFP ahead of the law's approval.
"Without strong safeguards to guard against the infiltration of organized crime (in the judicial selection process), an election system may become vulnerable to such powerful forces," she said.
The United States, Mexico's main trading partner, has warned that the reforms would threaten a relationship that relies on investor confidence in the Mexican legal framework.
The changes could pose "a major risk" to Mexican democracy and enable criminals to exploit "politically motivated and inexperienced judges," US Ambassador Ken Salazar said last month.
Human Rights Watch had urged lawmakers to reject what it called the "dangerous proposals," saying they would "seriously undermine judicial independence and contravene international human rights standards."