MEXICO CITY (AP) — Mexico’s Senate passed a bill early Friday handing control of the country’s recently created National Guard over to the military.

When the National Guard was created under a Constitutional reform in 2019, it was placed under civilian control. But most of its training and recruitment has been done from within the army.

President Andrés Manuel López Obrador says the guard must now be under military command, to prevent corruption. The lower house of Congress already approved the measure, and López Obrador is expected to sign it into law.

Opposition parties said late Thursday they will file court appeals, claiming the measure violates the Constitutional guarantee on civilian control.

“Public safety is not achieved by violating the rule of law, by violating the Constitution,” said Sen. Claudia Anaya Mota, of the Institutional Revolutionary Party, who vowed that opposition would quickly file a court challenge.

For years, Mexican politicians had widely agreed the country needs to improve its often corrupt, underpaid and ill-trained civilian police forces, and stop relying on military forces to fight drug gang violence. Even López Obrador had, earlier in his career called for soldiers to return to the barracks. He later said he changed his mind.

In 2019, the president dissolved the old civilian Federal Police and promised the National Guard — which unlike the United States, is completely federal and never commanded by state governors — would remain under the control of the civilian Public Safety Department.

But that created a bureaucratic headache for the armed forces, who supplied most of the National Guard officers from the ranks of the army and marines; those officers retained their place in the military, and were considered on-loan to the new force.

López Obrador no longer has enough votes in the Senate to change the constitution once again — that would require a two-thirds majority — and so his party simply changed the secondary laws governing the guard on a 71-51 vote.

Amnesty International said Friday’s vote “will lead to more human rights violations.”

“We have already seen the disastrous results of the militarization of public security forces in Mexico over the last 16 years,” Edith Olivares Ferreto, director of Amnesty International Mexico, wrote in a statement, referring to rights violations and increased violence.

Of the more than 110,000 members of the National Guard, more than 80% came from the army and the navy. The National Guard is only functioning because of the military leadership that organized it and the military’s extensive logistics capabilities.

The president has given the military more responsibilities than any Mexican leader in recent memory putting them in charge of not only battling drug cartels, but also fuel theft. He had them build a new airport for the capital and a tourist train on the Yucatan Peninsula. They build bank branches in rural areas and were key in the government’s response to the COVID-19 pandemic.

The military has been in the streets in a critical security role for years, well before López Obrador took office. It has been accused of human rights abuses and the United Nations has long called for it to be taken out of policing.

Neither the National Guard nor the military have been able to lower the insecurity in the country, however.

Critics say the National Guard lacks the investigative and intelligence capacities of a police force. They are a visible presence on patrols and respond to violence, but do little to prevent it.