“I urge other leading online companies to match or beat the commitments announced by Yahoo,” Mr. Markey said in a press release.

Previously, Yahoo kept search logs for 13 months. In September, Google began to strip out some personally identifiable information related to searches after 9 months. Microsoft keeps the information for 18 months.

The strongest pressure on Internet companies so far came from European regulators who have been urging major search engines to reduce to six months the time they hold personally identifiable information. Microsoft said last week that it would agree to such a standard if its rivals also went along.

Anne Toth, vice president of policy at Yahoo, said that the company chose an even shorter time period to “take the issue off the table.” Ms. Toth said she hoped that the new policy would make Yahoo’s search service more attractive with users concerned about privacy.

But it is not clear that stronger privacy protections will persuade consumers to switch to a different search engine. Last year, Ask.com introduced a new feature called AskEraser, which allows users to search anonymously. It has had little noticeable effect on the popularity of Ask.com. Google is the dominant search engine, handling about 63 percent of search queries in the United States, according to comScore.