MEXICO CITY - "Self-defense" groups confronting a drug cartel in the western state of Michoacan have agreed to join government law enforcement forces after months of firefights with gang members, many times as federal police and troops stood by.

The government announced Monday that it had reached a deal with vigilante leaders to incorporate the armed civilian groups into old and largely forgotten quasi-military units called the Rural Defense Corps. Vigilante groups estimate their numbers at 20,000 men under arms.

"The self-defense forces will become institutionalized, when they are integrated into the Rural Defense Corps," the Interior Department said in a statement.

Get Breaking News Delivered to Your Inbox

Vigilante groups began springing up almost a year ago against the Knights Templar cartel, which ruled many parts of Michoacan with an iron fist, demanding extortion payments from businesses, farmers and workers. The civilian forces have gained ground in recent months, seizing a number of towns from the gang, sometimes after intense gunbattles.

The rise in fighting proved an embarrassment for President Enrique Pena Nieto, drawing criticism that the administration brought on the rise of the armed groups by failing to stop the cartel's abuses, and the government hopes the agreement will help restore order and get it back in control.

More federal police and soldiers were dispatched to the troubled region after a particularly violent weekend early in January, but the vigilantes have refused to lay down their guns and return home until all of the cartel's major leaders are arrested. Officials announced that one of the cartel's top four leaders was captured early Monday.

Even before the new agreement, police and soldiers already largely tolerated, and in some cases even worked with, the vigilantes, many of whom are armed with assault rifles that civilians are not allowed to carry.

Vigilante leaders will have to submit a list of their members to the Defense Department, and the army will apparently oversee the groups, which the government said "will be temporary." They will be allowed to keep their weapons as long as they register them with the army.

The military will give the groups "all the means necessary for communications, operations and movement," according to the agreement.

Vigilante leaders, who include farmers, ranchers and some professionals, met to discuss the agreement, but it was not yet clear for them how it would work. It wasn't known if the army would offer anyone salaries.

Misael Gonzalez, a leader of the self-defense force in the town of Coalcoman, said the leaders had accepted the government proposal. But the nuts-and-bolts "are still not well defined," he added. "We won't start working on the mechanisms until tomorrow."

Vigilante leader Hipolito Mora said the agreement also allows those who qualify to join local police forces.

"The majority of us want to get into the police ... I never imagined myself dressed as a policeman, but the situation is driving me to put on a uniform," he said in an interview with Milenio television.

Security expert Jorge Chabat said the legalizations of self-defense groups is a positive step, both to return the rule of law to the state of avocado and lime farmers and to give protection to the vigilantes.

"In the long run it's not convenient for the rule of law to have armed groups that are outside the control of the state," Chabat said. "By being able to keep their weapons, now legally registered, they won't become victims of those criminal groups, because even if they arrest the (cartel) leaders there will be loose hit men who may want to take revenge."

The government said soldiers and police arrested one of the top Knights Templar leaders, Dionicio Loya Plancarte, alias "El Tio," or The Uncle, before dawn in the state capital, Morelia. National Public Safety System secretary Monte Rubido said Loya Plancarte was found "hiding in a closet" and accompanied only by 16-year-old boy.

Loya Plancarte had a 30 million-peso ($2.25 million) reward on his head wfor drug, organized crime and money-laundering charges and was listed as one of Mexico's three dozen most-wanted drug lords in the late 2000s.