Prime Minister Margaret Thatcher today staunchly defended last night's U.S. attack against Libya and her government's role in it, as she came under sharp criticism from her political opponents, much of the British public and many of Britain's allies in Western Europe.

The uproar here dramatized the political risks Thatcher was willing to take. Moreover, the fact that Britain was the only country that provided support and assistance demonstrated the difficulties of gaining any kind of agreement on such controversial actions within the North Atlantic alliance. France and Spain declined to provide overflight rights for U.S. warplanes flying out of Britain, while Italy and other allies continued to be critical of the action. Details on Page A23

The West German government today also criticized the American bombing raids in cautious tones that indicated a desire to limit a major row with Washington. Chancellor Helmut Kohl expressed understanding for U.S. distress over being victimized by terrorist attacks supported by Libya. But he stressed that Bonn opposed the military option exercised by Washington.

Thatcher said she had approved the use of U.S. F111 aircraft stationed here, first requested by Washington last week, after she became convinced that the aircraft were "essential" to the task, and that Article 51 of the United Nations Charter would provide legal justification on grounds of self-defense.

Sources said that those assurances, as well as American guarantees that targets in Libya would be "demonstrably associated with terrorism," were provided in writing by President Reagan in a letter delivered to Thatcher Saturday by special U.S. emissary Vernon Walters.

Thatcher, who earlier had examined both U.S. and British evidence against Libyan leader Muammar Qaddafi and found it conclusive, then sent a letter to Reagan agreeing that Britain would support an attack against Libya, and the use of British bases to launch it. Such agreement is required under a 1952 accord between the two countries.

Most Britons, including many politicians, did not know about the attack, which took place at about 1 a.m. local time, until they got up this morning. The initial response seemed to be anxiety on the part of the public, hostility from the political opposition and concern on the part of politicians in Thatcher's Conservative Party that she might not provide a good explanation both for them and the rest of the country.

Early morning radio talk shows were deluged with calls, most of them against the action and expressing resentment that Thatcher had exposed Britain to additional risk from terrorism. The U.S. Embassy also received a flood of calls from Britons opposed to the air strike.

Security inside and outside the embassy was stepped up today as at least one bomb threat was received, and a group of about 100 sign-carrying protesters massed for an all-day demonstration across the street from the mission.

Security also was stepped up at all British military and government installations and at international airports here. Tonight, a crowd of protesters estimated to number at least 1,000 gathered near Thatcher's residence at 10 Downing St.

Morning television devoted all of its programming to the raid, with repeated showings of footage from British correspondents in Libya of bombed civilian areas and wounded civilians -- many of them children -- to which the reporters said they had been directed by Libyan officials.

Thatcher made no public statement until she appeared at a packed and raucous House of Commons session this afternoon. Aside from interrogating Thatcher about specifics, there were more general attacks against the Reagan administration for opting for a military strike in the first place, and against Thatcher for supporting it.

"Far from bringing down the curtain on Qaddafi's reign of terror, as the president put it last night," said Neil Kinnock, head of the principal opposition Labor Party, "his adventure against Libya has failed to achieve that objective . . . has caused bloodshed and damage to innocents, and will result in a loss of American and British influence even with the moderate Arab states."

In one of a series of broadcast interviews, Kinnock said that Thatcher had "made herself an accomplice" of an attack that was made "without proper justification and without proper use of the alternative ways of bringing pressure to bear on Qaddafi."

Liberal Party leader David Steel said that "we have substantially increased military tension" in the Mediterranean, and pointedly asked whether Thatcher had written "a blank check to President Reagan."

David Owen, a former Labor Party foreign secretary who heads the Social Democratic Party, said that "the end, which we all share, of stopping Col. Qaddafi exporting terrorism, is not justified by these means, which are very hard to square with international law."

A series of more scathing comments in the House of Commons described Reagan as "cretinous" and Thatcher as his "poodle." "Your political infatuation with President Reagan," said one Labor member of Parliament, "is leading you to all the misjudgments of a giddy girl."

Although she appeared uncharacteristically weary and at less than her usual top debating form, Thatcher was firm and unequivocal.

In an opening statement, she said that her government had "evidence showing beyond dispute that the Libyan government has been and is directly involved in promoting terrorist attacks . . . and that it had made plans for a wide range of further terrorist attacks.

"The United States, after trying other means, has now sought by limited military action to induce the Libyan regime to desist from terrorism. That is in the British interest. It is why the government supports the United States' action," she explained.

Thatcher repeatedly returned to several points. "The United States," she said, "has more than 330,000 forces in Europe to defend our liberty. Because they are there they are subject to terrorist attack. It is inconceivable that they should be refused the right to use American aircraft and American pilots in the inherent right of self-defense to defend their own people," she said.

Although she acknowledged that civilians had been injured in the raid, Thatcher said that "some risks have to be faced in order to try to turn the tide against terrorism."

The United States, she said, had been repeatedly disappointed by "totally inadequate action taken by Europe over the past many years. I believe the United States was right and had a duty to invoke its right to self-defense."

For Britain to have refused to support the exercise of that right against Qaddafi "would have meant that we were supine and placid in the face of that terrorism," she added.

Thatcher gave short shrift to charges in Parliament that Britain had acted "duplicitously" in yesterday's meeting of the European Community. In pressing the other 11 members of the community to follow Britain's lead in breaking diplomatic relations with Libya, she said, Foreign Secretary Geoffrey Howe had warned them that failure to do so would strengthen the Reagan administration's justification for a military strike.

Although Labor leader Kinnock accused Thatcher of having made a unilateral decision without consulting other Cabinet ministers -- a charge of some seriousness in the British system of government -- Thatcher said that "the foreign secretary and secretary of defense" were with her "when the initial message from the president was received, and we have acted together in knowledge of one another's views throughout."

That information was likely to increase irritation within the European Community over the extent of Howe's knowledge of how far U.S. planning had progressed when he met with them yesterday in The Hague. Howe avoided a direct response to questions on the subject this morning.

Based on conversations with senior British and American sources, and Thatcher's own public statement today, the following sequence of contacts between Washington and London led to cooperation in last night's raid:

At about the middle of last week, officials from Reagan's National Security Council contacted their counterparts in Thatcher's Cabinet Office. The Americans said that the administration had decided to take military measures against Libya, and wanted both British backing and approval for use of Royal Air Force bases where U.S. Air Force F111s and some aerial refueling tankers are stationed.

Britain asked for extensive information concerning U.S. proof that Qaddafi and Libya were directly involved in terrorism. At the same time, sources pointed out, Britain had some evidence of its own to correlate with the U.S. information.

The two governments have a long and unique history of sharing intelligence information based on agreements dating from World War II. "There had been a lot of the stuff around, but without any smoking gun," said one source. "But in the last week" firmer evidence was produced relating to recent Libyan acts and imminent Libyan terrorist plans.

Thatcher's second area of questioning concerned the operational details of the proposed U.S. mission. Her staff requested that the NSC provide specific information on the types of bombs that were to be used, and on the intended targets. The British were told that the F111s were crucial because they were equipped with sophisticated avionics and radar equipment -- giving them all-weather reliability, automatic terrain-hugging ability that allowed the airplane to "fly itself" while the pilot pinpointed his target and watched for counteroffensive action from below -- and radar jamming equipment.

The United States, Thatcher told Parliament today, "made it clear that use of F111 aircraft from bases in the United Kingdom was essential because by virtue of their special characteristics they would provide the safest means of achieving particular objectives with the lowest possible risk both of civilian casualties in Libya and of casualties among United States service personnel."

Thatcher insisted that none of the targets be civilian or "indiscriminate," and that all be tied directly to terrorist planning or action.

By the time Walters arrived Saturday, most of these details had been ironed out. His meeting with Thatcher, along with Howe and Defense Secretary George Younger, sources said, concentrated primarily on the "public presentation" of the attack after the fact, including the extent to which evidence could be publicly revealed and the legal justification for it.