The first trial involving ultrarightists in democratic Spain opened here today with members of a neofascist group facing charges of murdering five persons in an attack on a communist law office in January 1977.

The tense hearing began as hundreds of youths belonging to the rightist New Force Party, chanting "the future belongs to us" and calling for "liberty for the Spanish patriots," were kept away from the central Palace of Justice law courts by squads of riot police.

Amid tight courtroom security, the first defendant to testify today said he acted out of patriotic motives.

"I fired . . . because it would let Spain live in peace," Jose Fernandez Cerra, 33, said under oath.

A civil suit being heard simultaneously with the criminal case will attempt to prove, during the expected week-long trial, that the fascist attack, known as the Atocha massacre, after the street where the law office stood, was part of a major conspiracy to destabilize Spain's transition to democracy. wSuch accusations about the extreme right's objectives have been revived following the recent escalation of ultraright terror linked to the growth of the New Force Party.

Fearing extremist violence, the Madrid civil governor banned all demonstrations today, canceled police leave and posted antiriot units downtown. dPreviously, leftist students had announced a "day of antifascist struggle" while the rightists had said they would hold a "red hunt" and mount counterdemonstrations.

The Atocha massacre came at a sensitive moment in the transition from Francoism to a consitiutuional monoarchy. Prime Minister Adolfo Suarez who had then still to complete his first full year in office, was intent on legalizing political parties and holding elections. Political circles now look back on the tense January 1977 days -- during which 10 percent died in political violence in the space of a week -- as a major hurdle in the democratic process when extremists from right and left were attempting to halt progress toward national reconcillation.

Those fears have surfaced once more as right-wing terror, in the form of shadowy groups styling themselves the Basque-Spanish Battalion and the Spanish Armed Groups, has added a new dimension to the violence endemic to Spanish political life.

Both groups are believed to be linked to the main party platform of the ultraright and Francoist diehards New Force, which gained 5 percent of the vote in the 1979 general elections in Madrid and a congressional seat for its demagogic leader Blas Pinar. The two groups which have claimed eight of the 27 political killings so far this year (the other 19 were the work of Basque separatists) are also widely believed to be linked to paramilitary police and state security services.

Those links came to the surface last week in a tense Congress debate over law and order during which the main socialist opposition party introduced a motion demanding that New Force be declared illegal. The demand came after two rightists, arrested in connection with the kidnap and murder of a Madrid student leader named Yolanda Gonzalez on Feb. 2, admitted that they were members of Pinar's party.

Following press reports that the detainees were connected to the state security service, Interior Minister Antonio Ibanez Freire ambiguously told Congress that members of the service were "related" to the killers but not "implicated" in the murder. The minister promised Congress a full investigation into the reports.

The same conspiracy theory lies behind the civil suit in the Atocha Massacre case. Lawyers in the suit told a press conference last week that they intended to uncover how the defendents came to be so well armed, how they were financed and how far they were motivated by Francoist politicans, among them Pinar.

The political killings have been paralleled by a growth of street violence and extremist clashes. The ugliest of the recent riots took place on Feb. 10 in the Madrid suburb of Vallecas, where the Gonzalez organized student and women's rights rights groups. It was caused by an attempt by New Force to hold a political rally in the area.

The rally provoked a violent reaction by local leftists, one of whom was killed.

In his testimony today, Fernandez Cerra, the first of the six defendants to be called, denied there was any goal of destabilizing the government behind the 1977 killings and retracted earlier statements that linked the shootings to members of the Francoist establishment and the security police. He faces between 33 and 39 years in prison if found guilty on charges of terrorism.