Belfodil broke the deadlock at the Opel Arena in the 12th minute to put Julian Nagelsmann's side ahead.
The effort extended the 27-year-old's tally to 16 goals after 28 league outings in his debut season with Die Kraichgauer.
Andrej Kramaric doubled the lead for the visitors in the 32nd minute but they failed to protect it after the restart.
Daniel Brosinski's effort from the penalty spot in the 66th minute inspired Mainz 05's comeback as Jean Boetius' double and Jean Mateta's goal in the closing stages completed the comeback.
The defeat ended Hoffenheim's hopes of progressing to qualifying round of the Uefa Europa League next season.
They finished their campaign in the ninth spot with 51 points after 34 matches.