The United States had warning of last weekend's bombing of a West Berlin discotheque that killed two persons, including an American soldier, and now has "indisputable evidence" that Libyan leader Muammar Qaddafi was behind the attack, according to NATO commander Bernard W. Rogers.

A highly placed government official yesterday confirmed Rogers' account but said the warning of a bomb attack in a specific area of West Berlin where American servicemen go for entertainment came through the U.S. intelligence net "days before" the discotheque was bombed. This official suggested that the administration reacted belatedly to the intelligence and was now attempting to put a favorable face on the situation.

Defense Department spokesman Fred Hoffman said he was "not in a position to comment" when questioned about the warning.

Gen. Rogers, speaking in Atlanta Wednesday, said, "The disco in Berlin, the evidence is there. We have indisputable evidence and I won't tell you how we get it because . . . well, I can't tell you how we get it. But it's there."

He said U.S. officials were attempting to warn off-duty soldiers at gathering places in West Berlin when the blast occurred early Saturday at the La Belle club.

"We were about 15 minutes too late," Rogers said.

Sixty-four Americans, many of them servicemen, were among the more than 200 injured.

As discussions of possible retaliation against Libya intensified, Rogers became the second high-ranking U.S. official this week to say that strong evidence exists linking Qaddafi to the bombing. Richard R. Burt, the ambassador to West Germany, has said there are "clear indications" that Libya was involved.

At the University of South Carolina yesterday, Sir Oliver Wright, the British ambassador here, also said there is "incontrovertible evidence that the Libyans have been the instigators of the most recent terrorist incidents."

President Reagan said in his news conference Wednesday night that the United States is prepared to respond militarily if there is proof that Qaddafi was responsible, but Reagan stopped short of saying there is definitive evidence linking the Libyan leader to the attack.

Meanwhile, two U.S. aircraft carrier groups sailed the Mediterranean to be in position should Reagan decide to order military retaliation. The Pentagon said the carrier USS Coral Sea -- its orders to proceed to Norfolk suspended -- steamed from the Spanish port of Malaga yesterday. The carrier USS America and its battle group already were at sea west of Sardinia after officials canceled a visit to Cannes on the French Riviera.

Britain's Lord Carrington, the secretary general of NATO, said in a television interview yesterday that "I don't think the United States can sit back and allow this sort of terrorism . . . without taking some sort of retaliatory action."

"What it would be, I don't know," he said on NBC's "Today" show. "I don't think you could say anything the United States would do would be supported by the Europeans. But I can tell you there would be a very great deal of sympathy and support for the United States doing something."

Presidential spokesman Larry Speakes yesterday refused to answer questions about Qaddafi or Libya. He did not dispute Rogers' statements, however.

Other administration officials have said the United States had warning of a possible terrorist attack in West Berlin. Before the La Belle club was bombed, they said, a warning was issued urging off-duty troops to avoid congregating in such nightspots. The officials were not specific about when the warning was issued.

The West German news agency DPA reported yesterday that West German authorities had determined that Qaddafi was behind the attack. Quoting "reliable sources," the news agency said Qaddafi had sent members of a Palestinian splinter group who carried out the bombing.

It also reported that days before the attack, radio contact between Tripoli and the Libyan "People's Bureau," or embassy, in East Berlin disclosed that something was about to happen in West Berlin, although the message was not specific. After the attack, a "message of success" was sent from the Libyans in East Berlin to Tripoli, DPA said.

On Capitol Hill yesterday, Sen. Sam Nunn (Ga.), ranking Democrat on the Armed Services Committee and a member of the Select Committee on Intelligence, complained about widespread disclosure of highly sensitive intelligence information.

Another senator, who declined to be identified, said that Rogers' statement about the United States having "indisputable evidence" linking Qaddafi to the bombing has further compromised the intelligence operations that led to the specific warnings prior to the attack.

Nunn was among several senators who said yesterday that if the Libyan connection to the bombing can be firmly established, Reagan will be justified in taking retaliatory action.

"Some kind of action would be required," Nunn said, adding that his preference was for economic reprisals. "Let's not buy their oil," he said. "This would be more effective than a military strike" if U.S. allies would go along with the boycott.

If Reagan should opt for a bombing strike, Nunn said he "will support the president. But the effect of military action should be economic in nature."

Sen. Carl Levin (D-Mich.), a member of the Senate Armed Services Committee who has disagreed with Reagan on many military issues, said that "if we have clear evidence" of the Libyan connection, the president would be justified "to retaliate in a measured way."

Levin also said he thought any evidence of such a connection "should be made public in some form."