The Spanish government legalized the Communist Party tonight, ending a ban imposed 38 years ago following the Civil War victory of the late Generalissimo Francisco Franco.

Communist leaders hailed the government's announcement that the party had been formally enrolled "in the oficial register of political parties."

The move, under consideration since the Supreme Court refused to rule on the party's legality a week ago, amounted to a peace treaty in the bloody conflict in which the main losers were the Communists and the main winners were Franco's rightist followers. Throughout his long dictatorship, Franco had singled out the Communist Party as responsible for violence and unrest in Spain.

The decision, opposed to the very end by die-hard military officers and rightists, was in keeping with the intention of King Juan Carlos, Franco's successor, and Premier Adolfo Suarez to relegate the Civil War and Franco's anti-Communist dictatorship to the history books.

It guaranteed full participation of the well-organized party in parliamentary elections later this spring and gave credibility to the government's contention that these will be Spain's first free elections in 41 years.

Legalization, did not come easily. The premier spent all week convincing last-ditch opponents, reportedly arguing: "We defeated them in the war and now we will defeat them at the polls."

Friends of the king were similarly engaged in explaining the most controversial political measure adopted by the monarchy since Franco's death 18 months ago.

The few Communist leaders in Madrid were jubilant. Executive committee member Ramon Tamanes remarked, "It's a glorious Saturday. The decision shows political common sense and ends a long period of darkness."

At party headquaters here, Communists celebrated the end of their long struggle to emerge from underground. The wife of a leader arrived with a party flag. Another brought a bottle of rum. Photographers and reporters filled the offices that were opened last summer when the government, indicating it was prepared to end Franco's suppression of the party, began tolerating Communist activities.

The party's general secretary, Santiago Carrillo, missed the event. He was in Paris visiting a sick relative. he told the Spanish news agency that the government's decision "strenghtened the march toward democracy." But he urged the premier to legalize all parties that have failed to win the government's approval. The Supreme Court recently refused to rule on the legality of 10 leftists parties.

"I consider (Premier) Suarez and intelligent anti-Communist who understands that ideas are not destroyed by repression and allegations of illegality," Carrillo was quoted as telling a Europa Press interviewer.

The party's strength today is estimated at between 10 and 15 per cent of the electorate. It is expected to win between 3 and 4 per cent of the seats in the June parliamentary election.

The state-controlled television and radio made the legalization of the party the main story in tonight's news.

Tamanes was interviewed and his comments were heard by millions.

While Franco lived, Communists were hunted down by police and jailed. Many were considered war criminals and lived in exile. Coming to Spain to work in the Communist underground was a major risk for party chiefs. Julian Grimau, a leader who fought in the Civil War and was captured by police, was ordered executed by Franco in 1963 despite pleas for clemency from world leaders.

Carrillo was the first general secretary of the party to operate in Spain since 1939. He entered Spain illegally last year after running the party from exile in France. He was arrested, however, after holding a clandestine press conference that embarrassed the government. But he was freed a few days later and permitted to campaign for increasing Communist membership.

Because anti-Communist was so deeply rooted among Spain's power elite, the government was reluctant to legalize the party. It sought to pass the decision to the Supreme Court last February, but the court handed it right back to the government.

Today's decision was endorsed by the attorney general and by the committee of state prosecuting attorneys, who found that the Communist Paty's by-law did not make the party illegal.