In twin raids, Spanish Police today rescued the country's fourth highest official and a top general from urban guerrillas who had held them for weeks here.

The spectacular police operation, which should help restore confidence in the government and in the security forces, overshadowed one of the most important political developments since the 1936-39 civil war - the outlawed Communist Party filed for legal status this morning.

The Communist Party's act, seen as a test of the government's democratization changing Spanish political scene as party leaders who had spent many program, was another landmark in the years in jail or exile entered the Interior Ministry for the first time as official visitors.

In the dramatic, rescue, police anti-guerrillas units supported by helicopters and armed police on the grounds, shot their way into two suburban apartments where the Oct. 1 Anti-Fascist Resistance Group, known as GRAPO, was hiding the two hostages. They are Antonio Maria De Oriul y Urquijo, 63, president of the Council of State, and Lt. Gen. Emilio Villaescusa, 64, presiden of the Supreme Military Tribunal.

Just before the rescue, a GRAPO gang killed one policeman and wounded another in Barcelona, the Interior Ministry said. He was the fourth law officer slain by the underground group in the past two weeks.

The rich and influential civilian official Oriol, kidnapped two months ago, and the general, abductd Jan. 24 were unharmed. Police arrested six persons in the two apartments, including Abelardo Collazo, considered GRAPO's leader. Official sources said that at least another 16 GRAPO members, who had eluded police for weeks were arrested elsewhere.

A police statement tonight said that a number of weapons were seized from the terrorists, including a gun stolen from three policemen that he underground organization killed Jan. 28 in Madrid area. The group emerged on Oct. 1, 1975, when it killed four law officers in the capital in retaliation for the exevution of five Basque and Maoist terrorist, ordered by the late dictator Francisco Franco.

First to be freed was the general who was in an apartment in Alcoron, a workers suburb in southwest Madrid, Shortly before police shot their way in, the kidnappers hauled Oriol out of the apartment and drove him to another hideout, official sources said.

Police helicopters and radio cars followed the car, and police later freed Oriol.

After abducting Oriol from his Madrid office in January, the terrorists said they would exchange him for 15 persons jailed for political violene. Later the underground changed its terms and said it would free Oriol, a close adviser of the king, if the government granted amnesty for nearly 200 political prisoners held for terrorism.GRAPO threatened to execute Oriol if its demands were not met.

Interior Minister Martin Villa, at a press conference tonight, refused to give details of the rescue. He would not confirm reports that several had been wounded in the raids.

The state-controlled television network hailed the rescue as a victory for police and the government, which had been under strong attack from rightist political leaders for its inabiliy to crack GRAPO.

There is no doubt that "Operation Achilles," as the effort to free the officials was called, boostd the image of the government, which has been criticized by the left for rightist violence and by the right for the slayings of police and street demonstrations by the left.

The climate of confusion and mistrust sparked by the terrorist killings and kidnappings not only threatened the government's democratization program plans to hold free parliamentary elections next spring, but sparked wild rumors. It was said, for example, that the two officials had been kidnapped by police, that U.S. Central Intelligence Agency was manipulating GRAPO, and that the Soviet Union's secret service, was involved.

But the tension did not deter Premier Adopho Suarez from pushing ahead with his reform programs. Earlier this week he lifted curbs on the legalization of political parties, opening the way for the Communists to apply for legal status.

The Communist Party, after considering a royal decree that transfers the power to deny legality to a party from the government to the Supreme Court, filed its application this morning.

Communist officials were confident that if their case went to the Supreme Court the party would emerge with legal status for the first time since 1939. The party was underground from the end of the civil war until Franco's death.