Flanked by Secret Service agents and deputy marshals, the witness entered the well of the courtroom, raised his right hand high and swore to tell the whole truth. His face and his hair had a familiar, powdered ghostly look, appropriate for a figure just emerged from the past. He positioned himself in the witness chair, an American flag behind him.

The prosecutor, John W. Nields Jr., coolly addressed the first question to the witness, called by the government to testify at the conspiracy trial of two former FBI aides at the federal court here.

". . . How are you employed?"

"I'm retired," the witness replied quietly.

"Were you once the president of the United States?"

"Yes."

For the next 46 minutes, interrupted only briefly by shouts from a few spectators who call him a "war criminal" and a "liar," Richard M. Nixon was once again in command, in the small, safe forum of a federal courtroom, explaining himself and the way things were when the country and his administration were torn by the Vietnam war.

The exchange betweeen Nixon and the prosecutor was a colloquy between gentlemen, not an interrogation.The former president didn't sweat, he didn't shake his head defensively and he didn't say he wanted to make anything "perfectly clear." He did sit back in his chair and ramble, his chin resting in his hand, and at times he pounded his finger on the wooden bench in front of him to emphasize a point, reminding his spellbound audience more than once that there are things "we have to understand."

And when he had the chance, Nixon was more politician than witness, his testimony more like a speech.

"As we sit here today, grave as our problems are, we can be fortunate that the United States at least is at peace in the world. And President Carter has made that point and I think he has every right to make the point that during his period and term in office, we have not at least in armed combat lost -- I think what -- and we have to understand what the attitude was then."

"Now, even now, at a time of peace, we are concerned about international terrorism. We are concerned, for example, when we read what happened in France recently, in Paris, the anti-Israeli activity resulting in assassination, murder and bombing, what happened in Italy and so forth. We are concerned it might happen here."

"But all these concerns, I can assure you as one who went through it, were greatly magnified -- I guess that's the proper word -- by the fact that in 1969, 1970, 1971 we were at war. . . .

"I can assure you that -- I think that, I hope that neither President Carter or Gov. Reagan if he should be president has to do what I had to do, what Franklin Roosevelt had to do --."

At that point, an impatient Chief Judge William B. Bryant interrupted and told defense lawyer Thomas A. Kennelly to ask his next question. But, Nixon continued.

" -- what President Truman had to do, that is, write letters to people whose sons have been killed in war. . . ."

Nixon's appearance last week, the first time he has testified in a courtroom since he left the White House in disgrace six years ago, was a stunning, final chapter in the trial of the two FBI aides, W. Mark Felt, once the bureau's No. 2 man, and Edward S. Miller, once chief of the domestic intelligence division. Both are charged with approving surreptitious entries -- known in bureau parlance as black bag jobs -- at the homes of friends and relatives of fugitive members of the radical Weather Underground in 1972 and 1973.

It had been rumored for weeks that the former president would appear as a witness for the defense, apparently anxious to testify that domestic terrorism, like that spawned by the Weathermen, hindered his efforts to end the war and justified efforts by the FBI -- including secret entries -- to penetrate that organization..

The defense, however, completed its case without calling the former president as a witness. Instead, the prosecution took up Nixon's offer to voluntarily testify for either side at the trial, a tactical decision by the government that could turn out to be a master stroke or a fatal blow to a delicate case, which is expected to go to the jury this week.

Nobody on the prosecution team is revealing any strategy, but a variety of courthouse observers have offered theories on the government's decision to have Nixon testify.

For one thing, Nields' questioning of the former president focused on Nixon's approval of the 1970 Huston plan, a domestic intelligence program aimed almost exclusively at the Weathermen and the Black Panther Party. The plan, Nixon testified, included illegal break-ins and electronic surveillance, but he said he believed his approval erased any illegalities. However, he then testified that he revoked his approval almost immediately, based on FBI Director J. Edgar Hoover's objections.

That testimony could be key to the prosecution, which argued that Felt and Miller needed direct approval from the president or from the attorney general to conduct the secret warrantless entries aimed at the Weathermen. There was no testimony from Nixon that he approved any entries other than those included in the Houston plan, which he withdrew. Nixon's statements capped testimony from four attorneys general, all of whom testified for the government that they never gave direct authority for surreptitious entries.

But Nixon's testimony, as expected, was also strongly supportive of the defense argument that the FBI director had direct authority from the president to carry out break-ins in national security cases against targets with established connections to hostile foreign powers. Nixon testified that it was his belief that a succession of presidents, dating back to Franklin D. Roosevelt, had passed that authority to the FBI director and that approval from the attorney general was not needed.

Some observers felt, however, that no matter how helpful Nixon's testimony was for the defense, it was doomed to be clouded by the stigma of Watergate, the crimes the public associates with the Nixon administration and the notion that the president and his men felt they were above the law. By calling Nixon, these observers said, the prosecution had imposed that stigma on the defense, a risk the defense thought it had avoided by turning down Nixon's offer to testify for it.