Updated

The Senate signaled an end Wednesday to months of rancorous debate over surveillance legislation that would protect from civil lawsuits the telecommunications companies that helped the government wiretap American lines.

By an 80-15 vote, the Senate turned back a last-ditch effort to kill the bill, setting up a vote to approve the measure on Thursday. The House passed the bill last week, and the Senate was expected to send it to President Bush for his signature.

Critics of the bill argue that immunizing the companies from lawsuits amounts to letting the Bush administration off the hook for nearly six years of warrantless tapping of phones and computer lines inside the United States following the Sept. 11 terrorist attacks. The surveillance took place without the permission — or even the knowledge — of a secret court created 30 years ago to oversee just such activities.

The bill amending the Foreign Intelligence Surveillance Act is a compromise reached after a monthslong standoff and weeks of negotiations between Democrats and Republicans. In exchange for telecom immunity, the inspectors general of the Pentagon, Justice Department and intelligence agencies will investigate the administration's warrantless wiretapping program.

The bill would also establish new rules to govern when the National Security Agency, CIA, FBI or other agencies can tap American phone and computer lines.

About 40 lawsuits have been filed by people and organizations who believe they were illegally spied on by the government with the companies' help.

The compromise bill would direct a federal judge to review certifications by the attorney general that the companies acted on the orders of the president, who told them wiretaps were needed to detect or prevent a terror attack. If the paperwork were deemed in order, the judge would dismiss the lawsuit. The judge would not, however, determine whether the warrantless wiretapping program itself was legal.

Opponents say lawsuits are the only way that Congress and the public will ever learn the full extent of the surveillance program. The White House said Bush would not sign a bill that did not immunize the companies.

The new surveillance bill would also:

—Require FISA court permission to wiretap Americans who are overseas.

—Prohibit targeting a foreigner to secretly eavesdrop, without court approval, on an American's calls or e-mails.

—Require the government to protect American information or conversations that are collected when in communication with targeted foreigners.

—Allow the FISA court 30 days to review existing but expiring surveillance orders before renewing them.

—Allow eavesdropping in emergencies without court approval, provided the government files required papers within a week.

—Prohibit presidents from superseding surveillance rules in the future.