The ruling on Tuesday by District Judge David Briones in El Paso, Texas, is the latest setback for Trump, whose administration has vowed to build at least 450 miles (724 kilometers) of wall along America’s southern border, Press TV reported.
The federal judge made the ruling in response to a lawsuit filed by El Paso County and the Border Network for Human Rights, an immigration reform group.
The judge said he did not want to minimize the importance of border security but “that concern cannot override the public’s interest in the Executive Branch complying with the law.”
In the lawsuit, the plaintiffs argued that Trump exceeded his authority when he declared the emergency and sought to redirect the funds.
Kristy Parker, the counsel for Protect Democracy – an organization that represented plaintiffs in the case, said in a statement that the order “affirms that the president is not a king and that our courts are willing to check him when he oversteps his bounds.”
Meanwhile, a spokesman for the US Justice Department said the White House would appeal the ruling.
Trump had promised to complete the construction of a border wall by November 2020, when the US presidential election will take place.
He has argued the wall will deter illegal border crossings, a major focus of his presidency.
The president declared a national emergency in February in order to transfer funds from the Pentagon to build the wall after Congress refused to provide $5.7 billion in funds that he demanded.
Congress gave $1.4 billion for wall construction, far less than what Trump wanted.
Top Democrats in Congress have criticized the project as wasteful and ineffective.
The latest ruling does not apply to $2.5 billion of Pentagon money that was initially meant for counter-drug operations and was redirected to wall spending in July.
The US Supreme Court granted an emergency order allowing that money to be spent during a legal challenge.