Baltimore County Executive Kevin Kamenetz signed an order Wednesday prohibiting county law enforcement from inquiring about the immigration status of anyone they encounter.

The order also says police and sheriff’s deputies cannot hold detainees past their release dates at the request of federal deportation agents, unless those agents have presented a judicial order.

“We do this because it promotes sound police practices,” Kamenetz (D) said at a news conference. “We want to continue to maintain the community trust among the residents we are obligated to protect. Driving people underground makes us less safe.”

The executive order broadly prohibits discriminating against people or withholding benefits based on their immigration status. It also limits police cooperation with federal authorities “except in the case of a criminal warrant signed by a judicial official.”

The measure mirrors a state bill that passed the House of Delegates last month but has stalled in the Senate. The legislation, known as the Trust Act, would apply similar policies statewide, with exceptions for jurisdictions participating in a special federal program that trains and uses local police for immigration enforcement.

Senate President Thomas V. Mike Miller Jr. (D-Calvert) has said the Trust Act will not pass in its current form, warning that “Maryland is not going to become a sanctuary state.” He added Wednesday that passing the bill could harm the state’s chances of landing the FBI’s new headquarters, for which plans are on hold.

Sen. Robert A. Zirkin (D-Baltimore County), who chairs a Senate committee reviewing the legislation, said Wednesday that the panel might advance a version of the bill that removes the language limiting detainment of undocumented immigrants while retaining parts that deal with questioning individuals about citizenship status.

CASA, an immigrant advocacy organization, said Baltimore County is the first large jurisdiction in Maryland to formally put in writing policies directly challenging the Trump administration’s promised crackdown on illegal immigration.

The executive order closely resembles “sanctuary” policies in cities and communities around the country that President Trump and Attorney General Jeff Sessions have said could cost those jurisdictions federal aid dollars.

The small city of Hyattsville passed a similar policy Monday night, and Fairfax County, Virginia’s most populous jurisdiction, passed a resolution Tuesday affirming that it welcomes immigrants.

Kamenetz said his signature represents the county’s “commitment to reject the unconstitutional and hateful agenda of the president.” He also urged lawmakers in the state’s Democratic-majority legislature to pass the Trust Act, which Gov. Larry Hogan (R) has vowed to veto.

Baltimore County receives about $110 million in federal grants for programs for senior citizens, veterans, the police department and mental health services — none of which have any direct relation to Trump’s immigration policy.

Kamenetz, who is weighing a bid to challenge Hogan in 2018, said Trump’s threats are “inconsistent with the Constitution and Supreme Court rulings” that say the federal government cannot use the denial of federal funds to coerce a jurisdiction into following specific policy directives that are unrelated to the allocation.

“We would challenge in court any efforts to deny funds,” he said.

Kamenetz previously directed Baltimore County police not to participate in efforts to identify undocumented immigrants among college students, saying he supported efforts by many universities to create “sanctuary campuses” after Trump’s election.