Sarhan bin Abd Al-Majid Farkhit, 35, known as El Tunecino (The Tunisian), was one of several men who yelled defiant Arabic slogans before detonating a charge that also killed a policeman, Interior Minister Angel Acebes told a news conference on Sunday.
Another of the dead, Moroccan Abd al-Nabi Kunjaa, was also among six suspects being hunted in connection with the 11 March bombings of four commuter trains, which killed 191 people.
Fifteen police officers were wounded by the explosion during the Saturday night raid in Leganes, a Madrid suburb. One of the wounded officers was in serious condition.
"The core group of those who carried out the terrorist act
(the train bombings) have been detained or died in the
collective suicide," Acebes said. "We have to highlight the
magnificent work done by the security forces."
Spain is holding 15 people, most of them Moroccan, over the
11 March attacks.
According to Spain's interior minister, the suspects, slain in the raid, "had planned other attacks and had the means to carry them out."
The police raid had "certainly prevented further attacks," he added.
Aljazeera's correspondent in Madrid, Taysir Aluni, said the fourth body, a female, was found in the swimming pool of the demolished building.
"An explosive belt which had not exploded earlier was found tied to the body," said Aluni.
"The dead woman might have been thrown to the pool when the first explosion took place," he added.
According to Aluni, the police started monitoring the suspects' residence few days ago, but began the raid on Saturday afternoon and finished it at 9:00pm (8:00 PM GMT).
Also on Sunday, two suspected members of armed Basque separatist group ETA have been arrested in France and a large cache of arms and explosives found, Spanish Interior Minister Angel Acebes said.
Angel Acebes says the suspects
planned more attacks in Spain
The discovery of the arms cache follows the arrest of three ETA leaders in France in the last few days.
Saturday morning raid came after Spanish police established that the dynamite in a bomb found on a high-speed rail track in Spain on Friday was of the same type and brand as used in the 11 March bombings.
Spanish authorities cast no light on who might be responsible for planting 12kg of explosives on the high-speed rail link between Madrid and the southern Spanish city of Seville, saying it was too early to point to any particular group.
Friday's bomb was defused after being spotted by railway workers.
Anti-Western Islamists are suspected of carrying out last month's bombings of the Madrid trains.
Signs that the dynamite used in the bomb found on Friday could be of the same Goma 2 Eco make used on 11 March has raised fears that Spain may be at risk of further attacks.
"It is the same type of explosives and the same brand," Acebes told a news conference on Saturday.
However, officials say Goma 2 Eco dynamite is commonly used in mining in Spain.
Asked if Spain suspected the Moroccan Islamic Combatant Group was to blame for planting Friday's bomb, Acebes said it would be hasty to conclude that a particular organisation was responsible.
Acebes had pointed to the Islamist group as the prime suspect in the 11 March attacks.
Acebes also said it was possible that the type of detonator found in Friday's bomb could be the same as ones used by the 11 March attackers.
"It is possible that some of this type of detonator may have
been in the possession of some of the groups that are being
investigated (over 11 March)," he said, adding the detonators too were typical of ones used in mines.