A US judge has ruled that an National Security Agency (NSA) program to wiretap telephone and Internet traffic of US residents is illegal and must be stopped.

Judge Anna Diggs Taylor ordered the NSA and "its agents, employees, representatives and any other persons or entities in active concert or participation" with the agency to halt the so-called Terrorist Surveillance Program.

The program allowed the NSA to monitor communications between US residents and people in other countries with suspected ties to terrorist group al Qaeda, without getting court-ordered warrants.

The program, authorised by President Bush in 2002, violates the US Constitution's guarantees of freedom of speech and association and its prohibitions against unreasonable searches and seizures, Taylor wrote in her order. The NSA program also violates the separation of powers clause in the Constitution, she wrote, as well as the Foreign Intelligence Surveillance Act, which set courts to issue warrants for wiretaps focused on counterintelligence."The public interest is clear, in this matter," Taylor wrote. "It is the upholding of our Constitution."

Bush has defended the program as a valuable tool used to track down potential terrorists. The program is "firmly grounded in law" and only targets international phone calls in which one participant is suspected to be linked to al Qaeda, Bush spokesman Tony Snow said in a statement. "We couldn’t disagree more with this ruling," Snow added. "The whole point is to detect and prevent terrorist attacks before they can be carried out. That’s what the American people expect from their government, and it is the President’s most solemn duty to ensure their protection."

The US Department of Justice has already appealed Taylor's order.