A fifth-place finish in the 1,500 metres, the final event, was enough to give a first global world title to the 25-year-old, who was Olympic silver medallist in Rio de Janeiro last year.
Mayer finished on 8,768 points with German pair Rico Freimuth (8,564) and Kai Kazmirek (8,488) taking the silver and bronze medals.
Twice former world champion Trey Hardee was one of more than a dozen of the original 35 starters who dropped out over the course of the notoriously tough contest which includes 10 different track and field disciplines over two days.
Mayer led from the shot put, the third event, and looked comfortable throughout except in the pole vault when he nearly wrecked his chances. After deciding to enter the fray at 5.10 metres, he missed his first two jumps and only narrowly made the third.
(Editing by Ed Osmond)