A mayor in Germany helped rescue a man who became trapped in a women's prison after mistaking it for a shortcut to a nearby park, police in the northern city of Hildesheim said.

Hildesheim mayor Henning Blum heard the man's cries for help while passing by the prison near the city centre and notified police, who came and freed the 24-year-old.

The man told police he was strolling through town and did not immediately notice he had walked into a prison.

By the time it dawned on him where he was, the gate to the jail had already closed, locking him inside.

Police said they are investigating why the prison gate was open, enabling the man to wander in.

- Reuters