A gunman stormed a lecture hall at Heidelberg University in southwestern Germany today, killing a young woman and injuring three others before fleeing the scene and turning the weapon on himself.

The man fired shots "wildly" around the amphitheatre, a police spokesman said.

He appeared to have no religious or political motive, German media reported.

All four victims were "seriously injured", police said. One of them later succumbed to her wounds in hospital, security sources said.

Police said the man was a "a lone perpetrator" wielding a "long gun", confirming that he had left the amphitheatre before killing himself.

At a press conference this evening, police said he was an 18-year-old German.

Mannheim police chief Siegfried Kollmar told the conference that investigators have learned that the gunman sent a WhatsApp text message shortly before the shooting that said "people have to be punished now" and that he wished to be buried at sea.

The shooting triggered a major police operation at the university's Neuenheimer Feld campus, with police on Twitter urging people to steer clear of the area "so that rescue workers and emergency services can travel freely".

Police said later that there was no longer any danger, adding that they were "not aware of any letter claiming responsibility" for the attack.

Germany's Justice Minister Marco Buschmann said his thoughts were with the victims, as he thanked emergency services for their deployment.

Heidelberg is a university town in the state of Baden-Wuerttemberg and home to a population of around 160,000 people.

Heidelberg University, founded in 1386, is Germany's oldest university and one of the most prestigious in Europe.

The university only resumed in-person classes in October after months of distance learning because of the coronavirus pandemic.

Students have to show they are vaccinated against Covid, recovered or in possession of a recent negative test if they want to enter university buildings.

The shooting triggered a major police operation at the university's Neuenheimer Feld campus

Germany has been hit in recent years by a spate of attacks, mostly perpetrated by jihadists or far-right militants.

School shootings however are relatively rare in Germany, a country with some of the strictest gun laws in Europe.

In 2009, a former pupil killed nine students, three teachers and three passers-by in a school shooting at Winnenden, also in Baden-Wuerttemberg. The gunman then killed himself.

In 2002, a 19-year-old former student, apparently in revenge for having been expelled, gunned down 16 people including 12 teachers and two students at a school in the central German city of Erfurt. He too then killed himself.

Both massacres were carried out with legal weapons and spurred Germany to tighten its gun laws.

The country currently requires anyone younger than 25 to pass a psychiatric exam before applying for a gun licence.

In another incident in 2016, nine people were killed when gunman David Ali Sonboly went on a rampage in a shopping centre in Munich.

The shooting sparked renewed debate about whether Germany should place further curbs on gun ownership.