Explaining the reason behind Tuesday's raid, police said they were looking for members of an Islamist group since March 11, the day an activist detonated his explosives belt in an internet cafe in Casablanca to avoid arrest.
Morocco has been on the alert for attacks since 2003 when 13 suicide bombers killed themselves and 32 other people in central Casablanca.
The attacks were allegedly undertaken as "punishment" for the North African country's strong alliance with the US in its "war on terror".
The day's drama began to unfold when police, apparently responding to a tip, surrounded a four-storey apartment building in the Hay al-Farah neighbourhood of the Fida area of Casablanca where the suspected bombers were holed up.
With the building under siege, one of the suspects fled to the roof, where he blew himself up, according to a police official who refused to give his name, saying he was not authorised to do so.
Morocco's official MAP news agency identified the bomber as Mohamed Rachidi, 37, and said he was part of a "terror cell" involved in the killing of a Casablanca police official in 2003.
A second man also appeared to be on the verge of detonating explosives, fumbling with his clothes, when a police sniper shot him, officials said.
The suspect later died of his wounds. He was identified by police as Mohamed Mentala.
Mentala was carrying 4kg of explosives, the ministry official said.
Mentala too was wanted by the Moroccan police for involvement in the 2003 bombings, the official said.
Ayyoub Raydi, the third man, blew himself up in the afternoon as police were searching the neighbourhood for him, officials said.
It was this explosion that killed a police officer, seriously wounded another and slightly injured a seven-year-old boy.
Broken glass and charred debris littered the street. Police cordoned off the area, erecting metal barriers to keep hundreds of onlookers back.
In Tuesday's final attack, five people were wounded, including two police officers, as a man blew himself up in the main thoroughfare of Hay al-Farah.
The bomber headed towards a group of police officers before detonating his charge, a police source said.
Moroccan officials say investigations into the March 11 cybercafe bombing had led police to a wider suspected plot to blow up foreign ships at the port of Casablanca, prominent landmarks including hotels in Marrakesh and Agadir, as well as police stations and tourist sites in Morocco.
|Police said the violent events began after|
a raid to arrest suspected fighters [AFP]
In that blast, Abdelfettah Raydi detonated his charge when the cybercafe's owner caught him surfing jihadist websites.
He was killed and four others were injured.
Authorities say the wider bombing plot uncovered by subsequent investigation involved at least 30 people.
The group had amassed dozens of kilograms of homemade explosives in a Casablanca apartment.
Police have so far arrested 31 suspects, who have been questioned by judges in preliminary court hearings.
Raydi and many other suspects were among some 2,000 arrested after the 2003 bombings, but were later released from prison under a royal pardon.