A shootout erupted at the hospital and left several people killed or wounded, police said. [AFP]

A prosecutor says four people have died and a policeman has been seriously wounded in a town in southwestern Germany after an explosion in an apartment building and a shooting in the neighbouring hospital.

Authorities believe the two events, which took place on Sunday, are linked.

Loerrach prosecutor Dieter Inhofer said that two people were found dead in an apartment building that burst into flames after an explosion on Sunday afternoon.

Inhofer said a woman, allegedly armed with a weapon, was seen running from the blast into the neighbouring St. Elisabeth hospital, where she reportedly opened fire, killing a member of the hospital staff.

He  said the woman then turned her gun on officers responding to the shooting and was killed in an exchange of gunfire. One police officer was seriously wounded.

"There was a very heavy exchange of gunfire in the hospital that had the potential to be very dangerous, but based on what we know right now ... no one else was injured," Inhofer said.

Joachim Langanky, a police spokesman, said firefighters found the bodies of a girl aged three or four years old and a middle-aged man - not a woman as they first thought - in the burnt-out apartment.

Police suspect they may have died before the explosion and fire because both bodies bore gunshot wounds. They said there was no immediate motive for the shooting.

Loerrach, a town of some 48,000 people, lies near Germany's borders with France and Switzerland.

The weekend incident comes only days after the manslaughter trial opened in Stuttgart last week of the father of Tim Kretschmer, the teenager who in March 2009 shot dead 15 people before killing himself at his old school.

Joerg Kretschmer, a 51-year-old businessman, is accused of having violated gun laws because his 17-year-old son was able to take his 9mm Beretta pistol from his bedside for his killing spree in the southern town of Winnenden.

Source: Agencies