The governor of Oregon and the Trump administration on Wednesday announced an agreement aimed at de-escalating tensions outside the federal courthouse in Portland, where federal agents have clashed with demonstrators during nightly unrest.

As part of the agreement, officials said, most Department of Homeland Security agents will leave the front lines around the courthouse and withdraw from Portland entirely if what they have deemed nightly rioting ­ceases.

But the timing of that exit remained unclear. Gov. Kate Brown (D) said the agents would pull out of downtown Thursday and depart the city soon thereafter. But acting DHS secretary Chad Wolf said the withdrawal was still a question of if, not when. He said federal officials would pull back from Portland “should circumstances on the ground significantly improve,” as state troopers move to protect the courthouse.

The uncertainty came as intense showdowns have continued between protesters and federal agents in Oregon’s biggest city, with federal actions drawing criticism from local officials and scrutiny from two inspectors general. The Trump administration has defended its response as a necessary move to keep people from attacking the courthouse.

Both sides say the agreement between Oregon and the Trump administration seeks to replace the highly scrutinized federal forces with state troopers and local police. The broader aim of the accord is to turn down the temperature by removing the most prominent symbols of the Trump administration: Homeland Security forces in tactical gear.

But it will immediately test the ability of state and local officials to control the streets, and the contrasting characterizations of the pact between Brown and Wolf were an indication that their newfound cooperation remained rocky.

Even before the announcement, tensions had receded in recent nights at the Portland courthouse. Crowds of protesters were smaller, and federal forces appeared less aggressive. Late Tuesday, amid news reports that Brown was negotiating to end the federal presence, a protester grabbed a microphone.

“We’ve got some news,” he said. “Governor Kate Brown is getting the feds out of Oregon!”

The crowd whooped and cheered.

But local protest organizers said the departure of federal agents — whenever it happens — will not end the protests. They said their original grievances, focused on racism and violence by the Portland Police Bureau, remain unresolved.

“These protests were never about Donald Trump, so the feds could leave tomorrow and the protests would continue. National media could leave tomorrow and the protests would continue. And that won’t stop until there’s massive changes to the PPB,” said Gregory McKelvey, 27, a community organizer who has attended ongoing demonstrations in Portland since they began, following the death of George Floyd in Minneapolis in late May.

McKelvey said Portland police had used heavy-handed tactics in the past. So, to him, the departure of federal officers was not necessarily an improvement.

“It’s like there’s this public fight between federal and local leaders over who gets to gas and beat us,” he said. “The feds’ gas is a little spicier, but honestly, does it really matter if you’re getting tear-gassed by the feds or tear-gassed by Portland police? The result is the same.”

Other cities are facing similar complaints about excessive force by law enforcement. On Wednesday, New York Mayor Bill de Blasio (D) criticized his city’s police after plainclothes officers with the warrant squad dragged a protester into an unmarked minivan on Tuesday.

Police said Nikki Stone, 18, was wanted for allegedly damaging police cameras near City Hall. De Blasio said the manner of the arrest — which happened in the middle of a march and was reminiscent of federal agents dragging protesters into unmarked vans in Portland — was inappropriate.

“It’s the kind of thing that we don’t want to see in this city,” de Blasio said. “This is not Portland.”

Also on Wednesday, the Justice Department said it will send additional federal officers into major cities, including Milwaukee, Cleveland and Detroit, to address violent crime through a separate program dubbed “Operation Legend.”

The effort will direct agents from the FBI; Drug Enforcement Administration; Bureau of Alcohol, Tobacco, Firearms and Explosives; and U.S. Marshals Service to join local task forces and work with cities to reduce rising crime rates.

“The most basic responsibility of government is to protect the safety of our citizens,” Attorney General William P. Barr said in a statement. “The Department of Justice’s assets will supplement local law enforcement efforts, as we work together to take the shooters and chronic violent criminals off of our streets.”

In Portland, federal agents from Customs and Border Protection and Immigration and Customs Enforcement will leave the front lines around the courthouse Thursday, but the Federal Protective Service — the DHS agency responsible for protecting federal properties around the country — will remain at the courthouse, with assistance from the Marshals Service, Wolf said. Some state police will join them inside the perimeter fence.

But state and federal officials issued contrasting interpretations of their own agreement. Wolf said there was no guarantee that federal officers would leave Portland, as the governor had said. Instead, the forces that had been at the front lines of the demonstrations would remain in the city, on standby, until Trump officials were satisfied with the effectiveness of the state and local response.

“Our entire law enforcement presence that is currently in Portland yesterday and in previous weeks will remain in Portland until we are assured the courthouse and other federal facilities will no longer be attacked nightly and set afire,” he told reporters.

“We will continue to reevaluate our force posture over time, as we do at every other facility around the country, and we will surge up and surge down, depending on circumstances on the ground,” he added.

Wolf also blamed local officials for having failed to do more to protect the courthouse in the past. Oregon officials have said it was the aggressive action of federal agents that inflamed the protests.

“No other city in the country has refused to work with federal law enforcement like Portland has,” Wolf said. “I’m glad that they are finally seeing the errors of their ways, and stepping up and doing what they should have been doing for the past 60 days, and that is partnering with federal law enforcement to do their job.”

Brown, in her own announcement of the agreement, assailed the federal response in Portland.

“These federal officers have acted as an occupying force, refused accountability and brought violence and strife to our community,” Brown said.

President Trump tweeted Wednesday that if the federal agents had not gone into the city, “there would be no Portland — It would be burned and beaten to the ground,” before warning that federal authorities could still go back. That statement exaggerated the scale of the protests, which have been limited to a small zone outside the federal courthouse.

Outside the courthouse on Tuesday evening, before the tentative drawdown was announced, a loudspeaker periodically blared out a warning not to touch the fence surrounding the building. “This is the Federal Protective Service,” it began. Protesters shouted and booed, largely drowning out the remainder of the message.

As the night stretched on, several people jumped the fence around the courthouse and wandered the graffiti-covered no-man’s zone inside. A man holding a pink rose shedding its petals meandered aimlessly. A person lit a firework near the entrance to the building. Another ran off as federal officers fired pepper pellets through a slit cut in the plywood at the front of the building.

Officers shone spotlights down on protesters in the crowd as those gathered chanted “Feds go home!”

Catherine Branch, 58, said she came down for the first time on Tuesday to stand in solidarity with Black Lives Matter and see what was going on between protesters and the federal agents.

“These government buildings that we all pay these tax dollars for are not serving everybody,” she said. “It saddens me to see what’s happening here every day.”

Midnight passed and still tear gas had not clouded the night — the first time in more than a week federal agents had held off for so long.

In the street beyond the fence, a couple meditated, sitting cross-legged on the asphalt. A man freestyled rap lyrics as a crowd gathered to watch. Protesters adjusted their helmets, took off their gas masks to breathe.

About 1:30 a.m., the federal agents declared an unlawful assembly and urged peaceful protesters to clear the area. The tear gas had been delayed, but it still came. About 2 a.m., agents emerged, firing tear gas and other munitions to clear the city streets.

Lang reported from Portland. Joshua Partlow and Jessica Wolfrom in Washington contributed to this report.