Both sides were keen to get onto the front foot in the early stages, and, despite a bright start from Mainz, it was Freiburg who created the first clear chance when Jonathan Schmid's powerful volley was kept out by Loris Karius.
However, the lead belonged to Mainz six minutes before the break when Jairo Samperio sprinted clear on the counter before squaring the ball to Shinji Okazaki, who tapped in the opener from close range.
Freiburg struggled to recover from the setback and, after Samperio sent out a warning by rattling the crossbar, Mainz doubled their advantage in first-half stoppage time as Okazaki slotted home his second after Nikolce Noveski's effort had been blocked.
The hosts looked much sharper after the break as they piled the pressure on, but Karius made a crucial save to keep out Nils Petersen's powerful low strike.
Mainz appeared to be cruising to victory until a frantic spell started with Freiburg reducing the deficit through Admir Mehmedi, who capitalised on space to curl an effort into the top corner from the edge of the box.
However, it looked as though there may be one final twist in stoppage time when Petersen headed the ball into the path of Schmid, who sprinted clear to make it 3-2.
Freiburg lofted a number of dangerous balls forward in the closing stages, but Mainz held firm to secure the win.