WASHINGTON — Until this week, entertainment industry executives thought they had the votes for new federal legislation cracking down on foreign websites that traffic in pirated movies and music and cost them billions.

They lined up support from the powerful pharmaceutical industry and labor unions, and organized an impressive bipartisan coalition in Congress.

Then Silicon Valley struck back and appears to have outflanked Hollywood.

The result was on full display Tuesday night as Wikipedia, Reddit and about 10,000 other sites shut down for a threatened 12- to 24-hour strike, said to be the Internet’s first such stoppage.

Jimmy Wales, Wikipedia’s founder, said the strike was meant to protest the legislation’s “frightening precedent of Internet censorship for the world.” Visitors to Wikipedia’s English-language site and others participating in the strike were met with a page urging them to write to Congress to oppose two proposed bills.

The swelling online opposition persuaded the White House to call over the weekend for lawmakers to remove the legislation’s most controversial provision, which would have required U.S. search engines and payment networks to block access to websites focused on pirated materials. Supporters of the legislation say it would target foreign websites trading in stolen intellectual property, including movies and music. Critics say it would unfairly penalize legitimate websites, too, such as the online classified ad service Craigslist or the photo sharing service Flickr.

Congressional sponsors are expected to remove the site-blocking provision and to try to forge a compromise that focuses largely on cutting off the money to foreign piracy websites.

While Hollywood and other backers focused their firepower inside the Beltway, tech giants such as Google Inc. and Amazon.com Inc., along with websites and online activists, made a broader case and took it mainstream.

They successfully shifted the debate from piracy to Internet freedom, calling the legislation a threat to free speech that could stifle the massive Web economy. And they waged an unprecedented online campaign to slow the momentum of the fast-moving bills and endanger their passage.

“It was assumed by everyone that the content owners were going to get what they asked for,” said Eric Goldman, director of the High Tech Law Institute at Santa Clara University School of Law. “What’s happened is that the opposition campaign has gone viral. It’s not just Silicon Valley speaking up, it’s the public at large.”

University of Southern California media professor Marty Kaplan said the Motion Picture Association of America is partly at a disadvantage because tech companies have a higher “brand appeal” in the general public.

“In the fight between a message that says, ‘The sites you love will be shut down’ and ‘The expensive content you love won’t be available,’ I think Silicon Valley wins that argument,” Kaplan said.

While all sides agreed that foreign piracy sites are a problem and preached the need to find consensus, that could be difficult given the inflamed rhetoric.

“It’s time to move forward on a narrowly crafted bill,” said David Hirschmann, president of the Global Intellectual Property Center at the U.S. Chamber of Commerce, a major backer of the legislation. “Whether the politics in an election year will allow for that, I still don’t know yet.”

The proposed legislation aims to cripple foreign-based websites that trade in pirated or counterfeit material by cutting off money from U.S. credit card companies and ad networks as well as removing the sites from search engine results, and in some cases blocking access.

Opponents said the legislation risks entangling legitimate websites and adding onerous legal costs to Internet startups.

“The definitions and language and provisions are extremely broad and extremely vague,” said Erik Martin, general manager at Reddit. “It would seem to be written without anybody who knew the technology.”

But supporters of the legislation said opponents are mischaracterizing it and criticized the planned protests.

Former Sen. Christopher J. Dodd, now chief executive of the MPAA, called the strike a “gimmick” and “PR stunt.” House Judiciary Committee Chairman Lamar Smith, R-Texas, said Wikipedia and other sites participating in the blackout were “promoting fear instead of facts.”

“Perhaps during the blackout, Internet users can look elsewhere for an accurate definition of online piracy,” Smith said.

The Hollywood movie studios and labor unions launched a group this summer called Creative America that has focused largely on lawmakers, sending more than 200,000 email petitions to Congress. The group also produced TV commercials highlighting their anti-piracy message — that foreign websites are stealing jobs in the U.S.

“We started this battle with strong legislative support and we still have that,” said Mike Nugent, executive director of Creative America. He called the planned blackout by Wikipedia and others an abuse of the process. “What they’re trying to do is extort cooperation from legislators and voters through blackout techniques,” he said.

The Senate plans to go ahead with a key procedural vote Tuesday on the PROTECT-IP Act in an effort to revise the bill and pass it within a week or two. The bill, which stands for Preventing Real Online Threats to Economic Creativity and Theft of Intellectual Property Act, has 40 co-sponsors.

Senate Judiciary Committee Chairman Patrick J. Leahy, D-Vt., the lead sponsor of the bill, is working on a package of amendments to address opponents’ concerns. He now says the site-blocking provision should be studied before being implemented, but it’s unclear whether he will propose removing it from his bill.

Smith said his committee would resume deliberations next month on its version of the legislation, the Stop Online Piracy Act. Last week, he committed to removing the site-blocking provision.

Capitol Hill opponents of the legislation called for more hearings. Sen. Ron Wyden, D-Ore., who has led Senate opposition to the pieces of legislation in the Senate and the House, said he plans to filibuster the vote to allow for more time to craft a compromise.

He has been working with Rep. Darrell Issa, R-Calif., on a narrower bill that targets the flow of money to foreign piracy sites through trade laws.

Wyden said the Internet strike and other actions by online activists would help narrow the bill further. “My goal has been … to keep our side in the ring … because we’re up against such powerful lobbyists,” Wyden said. “Now we go into the final rounds with a lot more strength.”