The Mexican government is facing a crucial test over the coming days as it moves to rein in armed militia groups across the mountain towns of Michoacan, the volatile western state where avocado farmers and lime pickers have banded together to drive out drug cartel gangsters.

While the “self-defense” movement has been celebrated in many corners of Mexico, it has also produced embarrassing images of teenage vigilantes running highway checkpoints and brandishing AK-47s and other weapons that are supposed to be illegal.

The government of President Enrique Peña Nieto began demobilizing the militias this weekend and replacing them with a new force, the Rural Police, whose ranks will be drawn from the vigilantes themselves.

But the government’s demobilization push has also created the potential for new clashes: between Mexican security forces and militiamen, but also among rival militias, including those that have boycotted the process and allege their former comrades are morphing into new, government-sanctioned criminal groups.

Peña Nieto has designated a high-ranking government lawyer from his inner circle, Alfredo Castillo, to manage the pacification plan, and on Saturday, Castillo stood before television cameras with the first 240 members of the Rural Police, handing a shiny new assault rifle to Estanislao Beltran, the squat, bearded militia leader known here as“Papa Smurf.”

But as they shook hands, other vigilante groups were refusing to lay down their weapons.

“Everyone is afraid that the government will make a deal and the cartel will come back,” said Eriberto Sanchez, a portly 30-year-old militiaman standing at a roadside bunker of fraying sandbags, a mother-of-pearl-handled Colt .38 pistol tucked in his belt. “We don’t have an honest government.”

If Mexican police and soldiers try to forcibly disarm the militias, “a lot of blood will be spilled,” he said.

The government’s strategy here carries significant risk for Peña Nieto, who has quieted doubts about his crime-fighting mettle in recent months by taking down several top cartel bosses, including Mexico’s most wanted trafficker, Joaquin “El Chapo” Guzman.

But bringing the rule of law to Michoacan, where the federal government has often been absent, or resented, will be nettlesome.

Castillo said the government has taken a flexible, patient approach. But he warned that in towns where the new Rural Police force has been activated, armed militiamen who refuse to stand down will face arrest.

“We want to avoid confrontation,” Castillo said in an interview. “We’re trying to reestablish harmony, order and peace.”

Asked when Michoacan last had those things, Castillo paused. “I don’t know,” he said.

A first for Mexico

The demobilization plan has produced extraordinary scenes in recent weeks, as Michoacan residents have convened en masse to register their weapons, including high-caliber firearms that have long been illegal for civilians to carry.

On a patchy soccer field guarded by teams of soldiers and federal police, local gun owners lined up for hours here last week, carrying old hunting rifles, shotguns and pistols — as well as the powerful AK-47s and AR-15s favored by cartel gunmen, and more recently, by the militias. Some in line munched on churros with one hand and cradled their guns with their other.

One by one, farmers in sombreros and grandmothers with floral handbags placed their thumb prints on government documents authorizing, for the first time in Mexico, their right to possess several types of weapons. Soldiers test-fired each gun into water-filled barrels to record its ballistic signature, data that can be matched to the weapon’s use in previous, and future, crimes.

“We don’t like this situation, but we can’t lay down our arms,” said Porfirio Avalos, a 52-year-old avocado grower who came with a rifle and a pistol.

Castillo said the military had registered more than 6,000 firearms prior to the weekend deadline, and more than 3,000 applicants had signed up to join the Rural Police — far more than they could initially accept.

The government says it does not plan to expand the registry beyond Michoacan, but Castillo acknowledged it could set a precedent in a country that had some of the hemisphere’s most restrictive gun laws on the books, yet a glut of illegal weapons on the streets.

Many of the militiamen said they were unconvinced by government’s assurances that it would not use the new database to take their firearms away and leave them vulnerable to criminals. And though prosecutors have not said it publicly, they say they plan to comb the new database to match the weapons’ ballistic profiles with old crime scene evidence.

Alfredo Viveros, an avocado grower and lawyer who has become a militia leader here, brought a long list of questions to the registry last week — but none of his guns. His cellphone rattled with text messages from fellow vigilantes seeking advice on whether to bring their weapons to the soccer field. Viveros told them to wait.

“What assurances do we have that you won’t take our guns away? The law hasn’t changed. They’re still illegal,” Viveros asked the commanding officer. “We’re supposed to keep these guns in our homes, but what happens if they come to attack my brother’s house and he needs my help?”

Genesis of the militias

Having faced down the once-fearsome Knights Templar drug cartel and survived, the militias show no signs of going away. Their sandbag bunkers are disintegrating after several months, but more durable fortifications are going up.

One group outside Tancitaro was busy last week mixing stones and cement to finish construction on a large, octagonal medieval-style gun turret to guard the checkpoint outside their dusty hamlet.

The state’s militia movement started last spring in Tepalcatepec, a hillside village of cattle ranches and mango fields, where the landowners met under a tin-roofed corral to plot revenge on the Knights Templar. The gangsters had dominated the town, shooting young men to get their girlfriends and choking the economy with steadily escalating extortion demands.

The leader who emerged, Jose Manuel Mireles, a lanky doctor who had spent years in Sacramento, drew on the networks of Michoacan immigrants in California to spread the message through Spanish-language radio and television programs and raise funds for his followers.

The movement grew from there. Convoys of pickup trucks raced from town to town, as fighters with yellow ribbons tied to their rifle barrels drove out the cartel in pitched gun battles for highways and central plazas.

But as the militia gained strength, its leaders came to resemble warlords, squabbling and turning on each other, particularly after Mireles was hospitalized after a plane crash earlier this year.

Last week the government-aligned militia leaders kicked Mireles out of their group, after he recorded a Web video personally challenging Peña Nieto and alleging his former comrades were in league with the gangsters. They include figures like Papa Smurf and Luis Antonio Torres Gonzalez, a former El Paso car salesman known as “El Americano,” who collectively accused Mireles of being mentally ill, irresponsible and crooked.

Mexico’s El Universal newspaper published a lengthy article Sunday detailing the 55-year-old Mireles’s relationship with his new 18-year-old girlfriend. Castillo also told reporters this weekend that Mireles is under investigation for murder. He then debuted the Rural Police in Tepalcatepec — Mireles’s home turf — meaning that any fighters loyal to him now risk arrest if they don’t disarm.

The rift threatens to explode into open violence. Death threats arrive “every day,” Mireles said in an interview, after returning home from Mexico City with a new armored Jeep Grand Cherokee. He vowed he wouldn’t cooperate with the government until it weeded out the criminals within the movement, which he wants to expand nationwide.

And if the government moves against militiamen who haven’t registered their guns, it will provoke a crisis, he warned.

“The war starts tomorrow,” he said.