NEW YORK >> New York City Comptroller and Democratic mayoral candidate Brad Lander was arrested by federal agents at an immigration court Tuesday after he linked arms with a person authorities were attempting to detain.

A reporter with The Associated Press and other journalists witnessed Lander’s arrest at a federal building in Manhattan, the latest confrontation between U.S. agents and a Democratic politician objecting to the Trump administration’s mass detention and deportation programs.

Lander was released from custody after a few hours. The U.S. attorney’s office said it was investigating his actions and would decide later whether to charge him with a crime. The immigrant Lander escorted out of the courtroom was also arrested.

Lander had spent the morning observing immigration court hearings and told an AP reporter he was there to “accompany” some immigrants out of the building.

His confrontation with agents unfolded quickly. As a group of agents moved in to detain a man who had exited a courtroom, Lander locked arms with the immigrant and demanded to see a judicial warrant. For more than 40 seconds, agents tried to physically separate the two, pulling both men down the hall in a chaotic scrum as photographers snapped photos.

Eventually, the agents wrested the two apart, then grabbed Lander’s arms and put them behind his back.

“You’re obstructing,” an agent told Lander.

“I’m not obstructing. I’m standing right here in the hallway,” Lander said as he was being handcuffed.

In a statement, U.S. Department of Homeland Security Assistant Secretary Tricia McLaughlin said Lander “was arrested for assaulting law enforcement and impeding a federal officer.”

After his release, Lander exited the building holding hands with his wife and accompanied by New York Gov. Kathy Hochul, a Democrat, to the cheers of a gathered crowd. He told reporters all he was trying to do was hold the arm of the man being detained and “certainly did not” assault an officer.

“I am happy to report that I am just fine. I lost a button,” Lander said, adding that he planned to return to the immigration court again as a form of nonviolent way of standing up to Trump’s immigration policies.

“I believe it is important to show up and bear witness and accompany people,” he said.

He added that the man “ripped” from his arms “doesn’t have a lawyer” and will likely sleep in an immigration detention center.

The episode occurred as federal immigration officials are conducting large-scale arrests outside immigration courtrooms across the country. In many cases, immigrants are arrested after a judge grants a government request to dismiss their case, making them eligible for expedited removal.

“They remove any opportunity for due process,” Lander had told reporters earlier in the day.

Lander’s arrest comes a little more than a month after Newark, New Jersey, Mayor Ras Baraka was arrested on a trespassing charge outside a federal immigration detention center in his city, although the charge was later dropped. Baraka’s fellow Democrat, Rep. LaMonica McIver, was charged with assaulting and impeding federal agents stemming from her role at the same visit as the mayor. She’s denied the charges.

Lander is a candidate in the city’s Democratic mayoral primary. Early voting in the contest is underway and the election is next week. Other candidates in the race quickly weighed in to criticize the arrest.