Telephone companies were facing as many as 40 lawsuits
The US senate has passed a bill to shield telephone companies who helped in the White House's controversial warrantless wiretaps programme.
The bill also grants the US government the power to continue with the telephone surveillance scheme.
The Bush administration faced criticism when details emerged of its programme to monitor the phone calls of foreign targets in the US without warrants.
Democratic presidential hopeful Barack Obama voted in favour of the measure.
His decision to back the bill drew criticism from some of his supporters, who pointed to past statements in which Mr Obama had pledged to block any bill which granted immunity to telecommunication companies.
"I wouldn't have drafted the legislation like this," said Mr Obama, in a statement on his website.
However, he added, "in a dangerous world, government must have the authority to collect the intelligence we need to protect the American people".
President Bush welcomed the Senate's decision to pass the bill, saying he would be signing it into law shortly.
The bill was passed in the House of Representatives with bipartisan support last month, after House Democrats reached a compromise with the Republicans over the provisions to grant telecommunications companies immunity from prosecution.
Telephone companies were facing as many as 40 lawsuits for their involvement in the scheme.
Previous attempts to pass the bill - and allow the warrantless wiretap scheme to continue - had foundered on the issue of immunity for telecom firms.
Democrats had been reluctant to grant the firms immunity, saying the courts should first determine what the companies did.
President Bush - backed by Republicans in Congress - wanted to ensure that firms which had helped his administration would not be liable for prosecution.
The two sides reached a compromise, whereby telephone companies would not be automatically immune, but courts would be obliged to dismiss a suit against a firm if it is able to produce written certification that the White House had asked it to participate in the programme and had assured the firm it was legal.