The Japanese forward scored his seventh and eighth goals of the season and set up Nicolai Muller for his eighth strike of the campaign to earn Thomas Tuchel's men all three points against Hamburg, who lost Tomas Rincon to a red card.
Hakan Calhanoglu and Rafael van der Vaart both scored for the northern Germany side, who end the year just two points above the relegation zone.
Mainz gave as good as they got in the early exchanges, but their first lapse in concentration in defence was punished.
Hamburg attacked with what seemed to be two forwards against three defenders, but Maximilian Beister noticed he had a man over, spreading play to his left to Calhanoglu, who had been left totally alone.
His angled shot found its way through two defenders and the Mainz goalkeeper, and just inside the near post.
Hamburg may have led, but they were not totally convincing and Mainz always looked capable of getting back into the game.
They did just that and more early in the second half with two goals in three minutes turning the game on its head.
First, an intelligent ball through from Yunus Malli set Okazaki up to beat Jaroslav Drobny with a composed finish, registering his sixth goal in his last eight appearances.
Okazaki then turned provider, pulling the ball back from the left to Muller, who moved one goal clear of his team mate again with his eighth of the season.
Hamburg levelled in bizarre circumstances in the 79th minute when Calhanoglu's sweeping cross slithered through the hands of Mainz goalkeeper Loris Karius to hit the post. Mainz failed to clear their lines and the ball came back in from the right to Van der Vaart, who bundled it in from close range.
It was not enough for a point, though, as Okazaki joined Muller on eight goals for the season with the last touch of the game, heading Zdenek Pospech's ball down before supplying the finish to lift Mainz into the top half of the table.