Mexican lawmakers passed sweeping measures overhauling the nation’s electoral agency on Wednesday, dealing a blow to the institution that oversees voting and that helped push the country away from one-party rule two decades ago.

The changes, which will cut the electoral agency’s staff, diminish its autonomy and limit its ability to punish politicians for breaking electoral laws, are the most significant in a series of moves by the Mexican president to undermine the country’s fragile institutions — part of a pattern of challenges to democratic norms across the Western Hemisphere.

President Andrés Manuel López Obrador, whose party and its allies control Congress, argues that the measures will save millions of dollars and make voting more efficient. The new rules also seek to make it easier for Mexicans who live abroad to cast online ballots.

But critics — including some who have worked alongside the president — say the overhaul is an attempt to weaken a key pillar of Mexico’s democracy. The leader of the president’s party in the Senate has called it unconstitutional.

Now, another test looms: The Supreme Court, which has increasingly become a target of the president’s ire, is expected to hear a challenge to the measures in the coming months.

If the changes stand, electoral officials say it will become difficult to carry out free and fair elections — including in a crucial presidential contest next year.

“What’s at play is whether we’re going to have a country with democratic institutions and the rule of law,” said Jorge Alcocer Villanueva, who served in the interior ministry under Mr. López Obrador. “What’s at risk is whether the vote will be respected.”

The watchdog, called the National Electoral Institute, earned international acclaim for facilitating clean elections in Mexico, paving the way for the opposition to win the presidency in 2000 after decades of rule by a single party.

Yet since losing a presidential election in 2006 by less than 1 percent of the vote, Mr. López Obrador has repeatedly argued, without evidence, that the watchdog actually perpetrated electoral fraud — a claim that resembles voter-fraud conspiracy theories in the United States and Brazil.

The Mexican leader’s skepticism about the 2006 election was even echoed last year by the American ambassador to Mexico, Ken Salazar, who told The New York Times that he, too, had questions about the results’ legitimacy.

President Biden’s top Latin America adviser later clarified that the administration recognized the outcome of that contest. The U.S. Embassy in Mexico has been sending reports to Washington assessing potential threats to democracy in the country, according to three U.S. officials who were not authorized to speak publicly.

But while some lawmakers have expressed concern about the electoral changes, the Biden administration has said little about the issue in public.

The American government sees little advantage in provoking Mr. López Obrador, and has faith that Mexican institutions are capable of defending themselves, several U.S. officials said.

The Mexican president remains extremely popular, and his Morena party is ahead in 2024 presidential election polls. One of Mr. López Obrador’s political protégés is likely to be the party’s candidate.

That dynamic has many in Mexico wondering: Why push for changes that could raise doubts about the legitimacy of an election his party is favored to win?

“We were looking to save money, without affecting the work of the I.N.E.,” Jesús Ramírez Cuevas, the president’s spokesman, said in an interview, using an acronym for the watchdog. The president has a “zero deficit” policy of austerity, he said, and would prefer to spend public money on “social investments, in health, education, and infrastructure.”

Mr. López Obrador has said he wants to make a bloated bureaucracy leaner.

“The electoral system will be improved,” Mr. López Obrador said in December. “They are going to shrink some areas so that more can be done with less.”

Many agree that spending could be trimmed, but say the changes adopted on Wednesday strike at the heart of the watchdog’s most fundamental role: overseeing the vote.

Electoral officials say the overhaul will force them to eliminate thousands of jobs — including the vast majority of workers who organize elections at the local level and install polling stations across the country. The changes also limit the agency’s control over its own spending and prevent it from disqualifying candidates for campaign spending violations.

Uuc Kib Espadas, a member of the watchdog’s governing council, said the changes could result in “the failure to install a significant number of polling stations, depriving thousands or hundreds of thousands of people of the right to vote.”

Mr. Ramírez Cuevas called those concerns “an exaggeration” and said “there won’t be massive layoffs” at the watchdog.

But the Mexican president has not hidden his disdain for the institution his party is now targeting.

After electoral officials confirmed his defeat in 2006, Mr. López Obrador led thousands of supporters in protests that paralyzed the capital for weeks.

He eventually led his followers off the streets, but never stopped talking about what he calls “the fraud” of 2006.

“He’s resentful of the electoral authority,” said Mr. Alcocer Villanueva, the former interior ministry official. “That resentment makes him act irrationally on this issue.”

Mr. López Obrador did not always seem determined to pare down the electoral body.

Mr. Alcocer Villanueva said that when he was chief of staff to the interior minister, from 2018 to 2021, he and his team proposed studying possible electoral changes, but the president said it was not one of his priorities.

Then the electoral watchdog started to get in the way of the president’s agenda.

In 2021, the agency disqualified two candidates from his party from running for office for failing to declare relatively small campaign contributions — decisions that some within the institution questioned.

“It was a disproportionate sanction,” said Mr. Espadas Ancona.

Soon, the president began spending a lot more time talking about the watchdog — usually negatively. In 2022, he mentioned it in daily news conferences more than twice as often as he did in 2019, according to the agency.

He has denounced the agency as “rotten” and “undemocratic” and made a punching bag out of its leader — a lawyer named Lorenzo Córdova — calling him “a fraud without principles.”

Mr. Córdova, who was appointed by Mexico’s Congress, has taken center stage in his own defense, responding directly to the president in a torrent of media interviews and news conferences.

“It is a very clear political strategy, to sell the I.N.E. as a biased, partial authority,” Mr. Córdova said in an interview, referring to the agency by its initials. “What is our dilemma as an authority? How do we handle it? If we say nothing, publicly, we are validating the president’s statements.”

The president’s critics have cheered Mr. Córdova’s willingness to take him on. But some in Mexico question whether Mr. Córdova has struck the right balance.

“He shouldn’t respond to the president so viscerally and with so much anger,” said Luis Carlos Ugalde, who led the agency from 2003 to 2007, adding: “It generates a stronger desire from the other side, from Morena, to attack and destroy the institute.”

Mr. Córdova stood by his approach.

“It’s very easy to judge from the outside,” Mr. Córdova said. “It’s been me who’s had to lead this institution in the worst moment.”

Mr. Córdova’s term will expire in April. Congress, controlled by the president’s party, will elect four new members of the watchdog’s governing body.

Oscar Lopez contributed reporting from Mexico City.