Andreas Ivanschitz gave Mainz the lead after 23 minutes before David Alaba equalised in the 83rd minute.
However, Soto struck the winning goal after 86 minutes to end a run of three games without a victory and move up to fifth place in the table with 40.
Ninth-placed Hoffenheim have not won in three contests and have tasted success just once in their last seven home matches to remain on 33 points.
The visitors nearly took the lead in the 21st minute as Sami Allagui collected Christian Fuchs' cross from the left and passed to Eugen Polanski, whose effort struck the post.
The guests went ahead just two minutes later with Allagui testing the Hoffenheim defence before being stopped by Marvin Compper. But Ivanschitz ran on to the loose ball and blasted his left foot effort just inside the left post.
Hoffenheim had two chances to equalise just before the half-hour mark as Ryan Babel was stopped by Mainz goalkeeper Heinz Muller, before Boris Vukcevic hammered the rebound wide.
Muller again was superb five minutes before the break, fending away Jan Kirchhoff's deflected ball from Sejad Salihovic's cross from the left side.
Hoffenheim keeper Tom Starke showed excellent reactions to stop Malik Fathi's header in the 55th minute.
The hosts tied the scores with seven minutes remaining when Muller failed to hold on to Gylfi Thor Sigurdsson's free-kick and Alaba pounced on the loose ball to score.
But Mainz regained the lead just three minutes later as Marcel Risse showed good pace down the right and crossed to Soto, who was quicker than Hoffenheim defender Andreas Beck and beat Starke.
Muller made a fine save two minutes later from Roberto Firminio to secure the victory.