Former president Richard M. Nixon took the witness stand in federal court here yesterday in an extraordinary display of courtroom drama and testified that he believes the director of the FBI had direct authority from the president to authorize break-ins in the interest of national security.

His testimony climaxed the trial of two former FBI officials charged with violating the civil rights of friends and relatives of the radical Weather Underground while Nixon was in the White House in the early 1970s.

Moments after the former president began his testimony in U.S. District Court, a woman seated in the crowd of spectators cried out, "War criminal!" Others followed with shouts of "genocide" and "He's a liar."

Secret Service officers rushed to Nixon's side, but the former president seemed undisturbed by the outburst, looking once toward Chief Judge William B. Bryant and raising his eyebrows.

As the shouts continued, deputy U.S. marshals quickly removed from the courtroom three demonstrators who have claimed they were victims of illegal FBI activity.

Much of Nixon's testimony focused on his efforts to bring an end to the Vietnam war while his administration was confronted with violent antiwar activists such as the Weathermen.

"It was quite different than what it is today," Nixon testified at one point, his eyes lowered.

The two FBI officials, W. Mark Felt, once the bureau's No. 2 man, and Edward S. Miller, formerly head of the domestic intelligence division, are charged with illegally authorizing warrantless searches of private homes in a desperate search for clues to the whereabouts of fugitive Weathermen.

The defense has repeatedly argued throughout the seven-week trial that authority to conduct those break-ins rested with then acting FBI director L. Patrick Gray III and that Felt and Miller had Gray's approval to conduct them. Yesterday, Nixon, called as a prosecution witness, testified that he, too, believed that the authority to approve those entries was passed on from the office of the president directly to the head of the FBI in national security cases.

"In matters of foreign intelligence, the line went directly from the president" to J. Edgar Hoover, the FBI director until his death in 1972, Nixon testified. When Gray succeeded Hoover as director the authority remained in the bureau. Nixon testified.

"It was the office not the man" that had the authority, Nixon testified during cross-examination by defense lawyer Brian P. Gettings.

Nixon, at times pounding his finger on the witness stand to emphasize a point, testified that in the early 1970s there was "hard evidence" that the Weathermen had connections to foreign powers, and he cited what he called that group's stated intention to "overthrow the government." Under questioning by Miller's lawyer, Thomas A. Kennelly, Nixon testified that he deemed it "essential" that the government strengthen its efforts to seek out persons responsible for bombings and other terrorist activities during the war years.

The former president, appearing as a court witness for the first time since he left office in August 1974, repeatedly emphasized that those years were a "war time" and that those violent disturbances "directly affected the president and those who advised him from bringing an end to a very difficult war."

"I can assure you as one who went through it" that concerns about terrorism were "greatly magnified . . . we were at war," Nixon testified at another point. He then said he hoped that neither President Carter nor Ronald Reagan, "if he becomes president," would have to "write letters to people whose sons had been killed" -- as he and other wartime presidents had to do.

Realizing he had digressed for a moment from his testimony about terrorism, Nixon apologized, and added, "When you have it [terrorism] in wartime . . . realize what's happening may create attitudes in this country that may delay the end of the war, the end of the killing, it makes it much worse."

During questioning by special government prosecutor John W. Nields Jr., Nixon testified that in 1970 he authorized a widespread domestic intelligence program -- known as the Huston plan -- involving illegal break-ins and electronic surveillance aimed almost exclusively at the Black Panther Party and the Weathermen. Nixon told Nields that he believed tha his approval, as president, of those activities in appropriate circumstances "would remove the illegality as I understood it."

Nixon said that four days after he approved the plan, however, he withdrew his authorization following objections from Hoover as conveyed to him by then attorney general John N. Mitchell.

Nixon testified, however, that in withdrawing his approval he did not think that he was prohibiting Hoover from using those techniques.

It appeared that the prosecution intended Nixon's testimony to show that the Huston plan was the only occasion when Nixon authorized the FBI to conduct warrantless searches directed at the Weathermen, and that he revoked that authority almost immediately.

Nixon, who now lives in New York, appeared voluntarily although the government had issued a subpoena for his testimony as a formality. Nixon has all along made it clear that he would testify in court for either side in the case, although the defense declined to call him and completed the presentation of its evidence Monday.

The case is expected to go to the jury within the next several days.