The leader of a militia that rounded up migrants at gunpoint along the U.S.-Mexico border has pleaded guilty to a federal weapons charge.

Larry Hopkins, who leads the United Constitutional Patriots, or UCP, faces up to 10 years in prison on one count of being a felon in possession of a firearm, according to a plea agreement entered Thursday in the U.S. District Court for the District of New Mexico.

The agreement, which must be approved later by a federal judge, brings the prosecution of Hopkins a step closer to resolution less than a year after videos surfaced showing militia members detaining migrants at the border.

The footage prompted a broad outcry, bringing intense scrutiny to UCP and other vigilante groups that took it upon themselves to scour the border for undocumented immigrants.

A lawyer for Hopkins, Kelly O’Connell, said the militia leader had decided to enter into a plea agreement in part because of health concerns. Hopkins was beaten by other inmates in jail shortly after his arrest, and claimed to have fallen on his head during a court appearance, according to O’Connell. He also worried that he had developed heart problems, O’Connell said.

“He described himself as in diminishing health. He had the overall feeling that he was getting worse and that it was possible that he wouldn’t survive in there,” O’Connell told The Washington Post on Friday. “I said, ‘The chance of you living well into your 70s gets a lot better if you’re not in this place.’ ”

A representative of the Doña Ana County jail in New Mexico could not immediately be reached for comment regarding Hopkins’s alleged beating or health issues.

O’Connell said he intends to seek a sentence of time served and probation for Hopkins, who has been locked up for roughly nine months.

The charge against Hopkins was not directly connected to UCP’s activities at the border but stemmed from the discovery of weapons in his residence in Flora Vista, N.M., in fall 2017.

In court papers, FBI agents said they visited his home after receiving a tip about “militia extremist activity.” They also said they received information that Hopkins had “made the statement that the United Constitutional Patriots were training to assassinate George Soros, Hillary Clinton and Barack Obama.”

Hopkins consented to a search, and agents found nine firearms, including several rifles, according to a criminal complaint.

The 70-year-old had previously been convicted of impersonating a peace officer and felony possession of a firearm, and he was barred from owning guns.

Federal prosecutors did not charge Hopkins until April 2019, after footage of the militia’s patrols circulated widely.

In one since-deleted video posted to Facebook, a large group of migrants, including several children, could be seen huddled together on the ground at night, their faces illuminated by flashlights.

“This is crazy, everybody, totally crazy,” a woman could be heard saying in the video, claiming that the group consisted of “hundreds” of people. “I don’t know what to say about this, other than the fact it’s got to stop.”

The video showed Border Patrol officers arriving and escorting the migrants away as the person with the camera followed close behind.

The footage was widely condemned by immigration advocates, civil rights groups and some law enforcement officials, including New Mexico Attorney General Hector Balderas (D), who said at the time that “the rule of law should be in the hands of trained law enforcement officials, not vigilantes.”

UCP was is one of several militia groups that started roaming the U.S.-Mexico border last year, inspired by a surge in caravans of migrants from Central America and by President Trump’s anti-immigrant rhetoric. A mission statement on UCP’s Facebook page said its goal was to “uphold the Constitution of The United States of America” and to protect citizens’ rights “against all enemies both foreign and domestic” — a phrase that mimics the oath taken by U.S. service members.

A U.S. Customs and Border Protection spokesman told The Post last year that the agency discouraged “private groups or organizations taking enforcement matters into their own hands.”

Kayla Epstein, Lindsey Bever and Eli Rosenberg contributed to this report.