At a meeting last week, Mr. Lieberman got into an argument with Mr. McCain, his closest ally and friend in the Senate, about his opposition to the bill. Mr. Lieberman questioned why Mr. McCain was doing the bidding of the U.S. Chamber of Commerce and asked what Mr. McCain would say if the nation was crippled by a cyberattack.

Mr. McCain angrily said his reputation on national security issues was unquestionable.

The Obama administration had tried to sell members of Congress on the need for the legislation through closed-door briefings from high-ranking national security officials and pleas from officials who had served in President George W. Bush’s administration about the looming threat of a catastrophic cyberattack.

After the vote, Ms. Collins said it was a “shameful day” and expressed disappointment with her fellow senators who lacked “a sense of urgency” about a looming cyberattack.

“We often hear the from members on both sides of the aisle, but particularly Republican members, that we need to be listening more to generals on the ground,” Ms. Collins said. “But listen to the generals who had responsibility in this area” who told members of Congress “over and over again” that the nation was not prepared for a cyberattack.

“I cannot think of another area where the threat is greater and we are less prepared,” she said.

The Senate Republican leader, Mitch McConnell of Kentucky, said that “no one doubts the need to strengthen our cyberdefenses.”

“We all recognize the problem, that’s really not the issue here,” Mr. McConnell said.

“It’s the matter that the majority leader has tried to steamroll a bill,” Mr. McConnell said, referring to Senator Harry Reid, Democrat of Nevada.

Despite threats of a veto from President Obama, the House passed its own cybersecurity bill in April, which called for more information sharing between national security and intelligence agencies and businesses.

The bill called for the government to provide businesses with classified information about cyberthreats and gave companies the option of sharing information about cyberthreats with the government. White House officials said the president opposed that bill because it called for too much information sharing between the government and businesses, which could have led to violations of Americans civil liberties.