The U.S. Senate passed legislation on Wednesday aimed at penalizing website operators that facilitate online sex trafficking, chipping away at a bedrock legal shield for the technology industry.

The bill passed the House of Representatives last month and was expected to be signed into law as soon as this week by President Donald Trump.

The legislation, which passed the Senate on a 97-2 vote, would make it easier for state prosecutors and sex-trafficking victims to sue social media networks, advertisers and others that failed to keep exploitative material off their platforms.

Law enforcement has lobbied for years for such a law, an effort which resulted in part from a crackdown on the online classified site backpage.com, which is used for sex advertising.

Passage of the bill represented a rare defeat for the technology industry, which for years has avoided regulation in Washington and opposed efforts to rewrite the decades-old Communications Decency Act. A section of that law protects internet firms from liability for content posted by their users and has long been credited for helping Silicon Valley's rapid growth over the past twenty years.

The Supreme Court in January 2017 refused to consider reviving a lawsuit against backpage.com that was filed by three young women who claimed that the website facilitated their forced prostitution, letting stand a lower court ruling because of the protection afforded by the Communications Decency Act.

Facebook Inc. and other technology companies and influence groups largely withdrew opposition to the measure after negotiating some changes that narrowed its potential impact.

Under the bill, victims would be required to show that a website knowingly facilitated sex-trafficking in order to file a successful lawsuit.

Sen. Ron Wyden, a Democrat, and Sen. Rand Paul, a Republican, cast the only votes against the bill.