Mainz, without a victory in nine outings, turned the form book inside out to defeat sixth-placed Stuttgart who were unbeaten in five games.
The home team had Eugen Polanski sent off in the 83rd minute and Stuttgart defender Maza was also dismissed in stoppage time.
Cacau put visiting Stuttgart in front six minutes after the break but two minutes later 21-year-old Ujah, signed from Norway's Lillestrom in the close-season, headed the equaliser.
Mainz went ahead on the hour following a harshly-awarded penalty for handball by Maza that was converted by midfielder Andreas Ivanschitz.
Four minutes later the Austrian set up Ujah for his second goal.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.