Mainz started brightly and Nicolai Muller had a chance to score from the centre of the box, but he put his effort straight at the goalkeeper.
The visitors started to control the game and Juan Arango fired high and wide from a tight angle in the box.
Then with the first half about to come to an end, Bo Svensson fouled Mike Hanke in the box and Branimir Hrgota smashed his penalty high for the equaliser.
There were goals galore in the second half as first Hrgota got his second inside the opening 15 minutess.
Hanke put the visitors 3-1 up six minutes later before Hrgota completed his hat-trick with 10 minutes left.
A very late Andreas Ivanschitz penalty proved to be just a consolation for the hosts, who had been soundly beaten 4-2.