PORTLAND, ORE. – After flooding the streets around the U.S. courthouse in Portland with tear gas early Friday, dozens of federal officers in camouflage and tactical gear stood in formation around the front of the building.

Then, as one protester blared a soundtrack of “The Imperial March,” the officers advanced. Through the acrid haze, they continued to fire flash grenades and welt-inducing marble-size balls filled with caustic chemicals. They moved down Main Street and continued up the hill, where one of the agents announced over a loudspeaker, “This is an unlawful assembly.”

By the time the security forces halted, the federal courthouse they had been sent to protect was out of sight — two blocks behind them.

The aggressive incursion of federal officers into Portland has been stretching the legal limits of federal law enforcement as agents with batons and riot gear range deep into the streets of a city whose leadership has made it clear they are not welcome.

“I think it’s absolutely improper,” Oregon Attorney General Ellen Rosenblum said in an interview Friday. “It’s absolutely beyond their authority.”

The state lost its bid Friday for a restraining order against four federal agencies on the grounds that the state attorney general lacked standing, but several other challenges are still making their way through the courts.

Federal officers who arrived this month to help control protests over racial injustice and police violence have made dozens of arrests for federal crimes, including assaults on federal officers and failing to comply with law enforcement commands. More than 40 protesters have been arrested, and dozens now face federal criminal charges.

One protester standing on a city street outside the federal courthouse was shot in the head with a crowd-control munition, leaving a bloody scene and a serious facial injury that required surgery. In another incident, an officer was seen repeatedly using a baton to whack a Navy veteran who said he had come to speak to the agents. Videos taken by members of the public captured camouflaged personnel pulling protesters into unmarked vans.

The inspectors general of the Department of Justice and the Department of Homeland Security have opened investigations.

During 57 consecutive nights of protests, demonstrators have squared off first with Portland police and then with federal agents in what at times have been pitched battles, with protesters throwing water bottles or fireworks and agents responding with frequent volleys of tear gas. The arrival of federal agents caused the protests to swell and focused the ire of protesters onto the Mark O. Hatfield U.S. Courthouse, across from a park shaded by mature trees.

What began as a movement for racial justice became a broader campaign to dislodge the federal forces from the city.

The federal agents from four agencies arrived after President Donald Trump signed an executive order June 26 ordering the protection of federal monuments and buildings.

There is broad agreement among legal scholars that the federal government has the right to protect its buildings. But how far that authority extends into a city — and which tactics may be employed — is less clear.

Robert Tsai, a professor at the Washington College of Law at American University, said the nation’s founders explicitly left local policing within the jurisdiction of local authorities.

He questioned whether federal agents had the right to extend their operations blocks away from the buildings they are protecting.

“If the federal troops are starting to wander the streets, they appear to be crossing the line into general policing, which is outside their powers,” Tsai said.

Homeland Security officials said they are operating under a federal law that permits federal agents to venture outside the boundaries of the courthouse to “conduct investigations” into crimes against federal property or officers.

John Malcolm, vice president for the Institute for Constitutional Government at the conservative Heritage Foundation and a former deputy assistant attorney general during the George W. Bush administration, said federal agents have clear legal authority to pursue protesters who have damaged federal property.

“Once they have committed a crime, the federal authorities have probable cause to go arrest them,” he said. “I don’t care how many blocks away they are from that property.”

While federal authorities are not intended to be riot police, he said, the federal government has the authority to send in troops in extreme situations in which there is a breakdown of authority and local officials are unable to effectively enforce local laws.

“But we are not there yet, and I pray that we don’t get there,” Malcolm said.

Outraged by the federal presence, government leaders in Portland have been looking for ways to push back against the deployment. The Portland Police Bureau ousted federal representatives from the city’s command post. Mayor Ted Wheeler, who himself was hit with tear gas fired by federal agents Wednesday night, called the federal deployment an abuse of authority.

“My colleagues and I are looking at every possible legal option we have to get the feds out of here,” the mayor said.