A bill that would end the National Security Agency’s bulk collection of Americans’ phone records cleared a major hurdle in the House on Thursday and will head to the floor, where it is widely expected to pass.

The House Intelligence Committee by a unanimous voice vote endorsed the USA Freedom Act, which a day earlier the Judiciary Committee approved in a surprising 32 to 0 vote.

The Thursday vote reflected a rare congressional success at bridging partisan and policy differences on an issue that has deeply divided lawmakers and the public ever since former agency contractor Edward Snowden first disclosed in June broad NSA surveillance.

But it was almost upended at the eleventh hour when the Intelligence Committee circulated a proposal late Wednesday night to amend the USA Freedom Act in a way that would have weakened privacy protections, creating an uproar among Judiciary Committee members.

By Thursday morning, however, the intelligence panel, which had produced a competing bill, decided to stick with a deal reached earlier this week to agree to the judiciary panel’s amended bill.

“I was strongly opposed to the original USA Freedom Act because it made us less safe,” Rep. C.A. Dutch Ruppersberger (Md.), the Intelligence Committee’s ranking Democrat, said at the opening of a session Thursday to consider the legislation. But, he said, “there has been a drastic improvement to where the judiciary bill was originally. From our vantage point . . . this is a great bipartisan compromise.”

In the NSA program, the agency receives from several phone companies all call detail records — phone numbers dialed and call lengths and times, but not recordings of conversations. The data is used for counterterrorism purposes.

The USA Freedom legislation would bar the government from such bulk collection, and not only of phone records, but financial, health and other types of personal information as well.

The bill would instead require the NSA to seek a judge’s permission to ask a phone company to query its databases for records linked to a particular terrorism suspect’s phone number.

The Intelligence Committee in March issued its own proposal, which also would have barred the bulk collection of phone records but did not require judicial approval before the government sought information about a number.

President Obama in January called for an end to the NSA’s bulk collection of phone records. He said he wanted Congress to pass legislation that would require government agents to go to court before they could have a phone company pull the records of individual numbers.

To reach a deal, the intelligence panel leaders agreed to that. The Judiciary Committee said it would drop a requirement that any records sought be linked to a suspect who is the subject of an investigation.

Intelligence panel leaders still have concerns that the bill would limit the FBI’s flexibility to conduct investigations, which aides said they hope can be worked out before the legislation reaches the floor.

Privacy advocates have some concerns about the legislation that they hope can be addressed in the coming weeks.

“The bill is admittedly an imperfect compromise,” said Kevin Bankston, policy director of the New America Foundation’s Open Technology Institute. “But make no mistake: USA Freedom, if passed, would still be the most powerful new law to regulate government’s national security surveillance powers since the spying scandals of the ’70s prompted Congress to pass the original Foreign Intelligence Surveillance Act.”

The legislation could be taken up on the floor as soon as the week of May 19. The Senate has yet to advance its version of the bill.