U.S. District Court Judge Lewis Kaplan has granted a restraining order preventing the Trump administration from withholding counterterrorism funds from New York City's Subway system.

In a ruling on Wednesday, Kaplan sided with New York Attorney General Letitia James, noting that "3,000 people died within sight of this courthouse" during the terrorist attacks on Sept. 11, 2001.

Congress required the Department of Homeland Security to distribute the funds "solely" on the risk of terrorist attacks, the judge said.

"New Yorkers lived through the worst terrorist attack in our nation's history, and we know what is at stake here," James said in a statement before the ruling. "Congress created this program after 9/11 to protect millions of daily riders. I am asking the court to act before midnight to stop these funds from vanishing and to ensure that New Yorkers are not put at risk by this administration's political games."

President Donald Trump reportedly ordered his government to withhold the funds in response to the city's "sanctuary" policies on immigrants.