California Gov. Jerry Brown has reached an agreement with Homeland Security and Defense officials on the terms of his state’s National Guard deployment to the border, after insisting the troops will not be used to help U.S. agents enforce immigration laws.

Wednesday’s announcement follows several days of back-and-forth posturing between the White House and the Democratic governor, whose state’s “sanctuary” policies protecting undocumented immigrants are a frequent target of President Trump’s exclamatory Twitter barbs.

Brown said California will deploy 400 soldiers who will work against drug trafficking and cross-border criminal groups but eschew contact with border-crossing migrants.

“California National Guard service members shall not engage in any direct law enforcement role nor enforce immigration laws, arrest people for immigration law violations, guard people taken into custody for alleged immigration violations, or support immigration law enforcement activities,” his order states. “California National Guard service members shall not participate in the construction of any new border barrier.”

The agreement he announced Wednesday appeared to be a compromise between Trump and a man he mocks as “Governor Moonbeam.” Their deal gives Trump the full participation of every border state in his plan to reinforce federal agents with Guard troops, while allowing Brown to join the effort on his own terms.

Brown’s announcement followed two days of Twitter criticism from Trump. “Jerry Brown is trying to back out of the National Guard at the Border, but the people of the State are not happy. Want Security & Safety NOW!” Trump posted early Wednesday.

His tweet came a day after the chief of the U.S. Border Patrol and two Pentagon officials said California had rejected the terms of their initial request for a troop mobilization in the state.

Texas, New Mexico and Arizona — all led by Republican governors — were quick to mobilize troops for Trump’s border deployment and have sent nearly 1,000 troops so far. The Pentagon has authorized as many as 4,000 soldiers but has not said what their assignment will cost or how long it could last.

California had been the only holdout, with Brown saying publicly he did not want soldiers helping U.S. agents arrest families and children fleeing violence in Central America.

The order he issued Wednesday indicates that up to 400 California Guard troops will join 250 already deployed in the state, and they would not be limited to operations along the border. Some will support counternarcotics efforts within the state and along the maritime routes sometimes used by smugglers trying to land drug shipments on California beaches.

The troops will “combat the non-linear threat of transnational crime that extends to areas of California beyond the U.S.-Mexico border,” Brown’s order states.

Additionally, Brown said the troops should decline to join any missions that “compromise the state’s ability to respond to state emergencies,” and “missions that do not meet a valid state and/or national security interest,” as well as those that would draw troops into an immigration enforcement role.

Pentagon and Homeland Security officials have said the Guard troops will not arrest migrants or be required to carry weapons, and will instead spend their time helping by providing transportation, conducting surveillance and offering other forms of support to U.S. Border Patrol agents. But Brown wanted additional limitations on the California Guard troops barring them from assisting with immigration enforcement.

The California troops will begin their deployment before the end of the month, his order states.