Mexican legislators approved a series of contested reforms that would make it the first country to let voters elect all judges, shortly after protesters stormed the Senate to disrupt the debate.
Outgoing President Andres Manuel Lopez Obrador had pushed hard for the reform, criticizing the current judicial system as serving the interests of the political and economic elite.
The leftist leader hailed the bill's approval, saying Mexico would be an "example to the world."
"It's very important to end corruption and impunity. We will make great progress when it is the people of Mexico who freely elect the judges, the magistrates, the justices," the 70-year-old told a news conference.
The reform was approved with 86 votes in favor and 41 against in the early hours of the morning, garnering the two-thirds majority needed to amend the constitution, in an upper chamber dominated by the ruling Morena party and its allies.
The reforms have sparked mass demonstrations, diplomatic tensions and investor jitters.
Senate leader Gerardo Fernandez Norona had declared a recess after demonstrators stormed the upper house and entered the chamber, chanting "The judiciary will not fall."
Lawmakers were forced to move to a former Senate building, where they resumed their debate as demonstrators outside shouted "Mr. Senator, stop the dictator!"
Lopez Obrador, who wanted the bill approved before close ally Claudia Sheinbaum replaced him on Oct. 1, accused protesters of protecting the interests of the political elite.
The reforms have the full support of Sheinbaum, who said Wednesday they would strengthen the justice system.
"The regime of corruption and privileges is becoming more and more a thing of the past," she wrote on social media platform X.
The plan, which had already cleared the lower house, must now be approved by 17 of 32 state congresses – considered a formality given the ruling coalition's political dominance – before being signed into law by the president.
Opponents, who accuse Lopez Obrador of overseeing a trend toward democratic backsliding, have held a series of protests against the plan, under which even Supreme Court and other high-level judges, as well as those at the local level, would be chosen by popular vote.
Judges will have to stand for election in 2025 or 2027.
"This does not exist in any other country," Margaret Satterthwaite, U.N. special rapporteur on the independence of judges and lawyers, told AFP ahead of the vote.
In an unusual public warning, Supreme Court Chief Justice Norma Pina said that elected judges could be more vulnerable to pressure from criminals, in a country where powerful drug cartels regularly use bribery and intimidation to influence officials.
"The demolition of the judiciary is not the way forward," she said in a video released on Sunday.
Pina said last week that the top court would discuss whether it has jurisdiction to halt the reforms, though Lopez Obrador has said there is no legal basis for it to do so.
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," U.S. Ambassador Ken Salazar said last month.
Financial market analysts say investor concerns about the reforms have contributed to a sharp fall in the value of the Mexican currency, the peso, which has hit a two-year low against the dollar.
Satterthwaite has also voiced "deep concerns" about the plan, calling access to an independent and impartial judiciary "a human right essential for protecting rights and checking power abuses."
"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 warned.
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."