WASHINGTON — The House of Representatives late on Thursday voted to bar the National Security Agency from looking for Americans’ communications without a warrant within a database of emails and phone calls it gathers while targeting foreigners, a technique critics have labeled a “backdoor search loophole.”

By a 293-to-123 vote, the House approved the ban as an amendment to the 2015 defense appropriations act. A version of the proposal had been a component in the original version of the USA Freedom Act, legislation the House passed last month that was aimed at curbing N.S.A. spying, but it had been stripped out in negotiations among congressional leaders.

The proposal has drawn opposition from security agencies and still has a long way to go before it would become law. But the chief sponsors of the provision — Representatives Jim Sensenbrenner, Republican of Wisconsin, Zoe Lofgren, Democrat of California, and Thomas Massie, Republican of Kentucky — celebrated the lopsided vote.

“There’s no question Americans have become increasingly alarmed with the breadth of unwarranted government surveillance programs used to store and search their private data,” they said in a joint statement. “By adopting this amendment, Congress can take a sure step toward shutting the back door on mass surveillance.”