Marc Gasol added 13 points and 14 rebounds for Memphis, which is in the midst of playing seven games in nine days. The Grizzlies opened the stretch with a 98-89 loss at Houston on Friday.
Brandon Jennings scored 24 points on 9-of-18 shooting for Milwaukee.
Ersan Illyasova added 18 points and 15 rebounds for the Bucks, who were coming off a 37-point victory at Cleveland on Friday — their largest margin of victory since Feb. 20, 2002.
Mayo and Gay each came up big in the second half to help Memphis win for the third time in four games. Mayo scored 15 points after halftime and Gay, who missed all six of his shot attempts in the first half, had 14.
After Gasol slapped the ball out of Drew Gooden's hands as he went up for a shot near the lane, Mayo hit a 3-pointer from the left wing to give Memphis its biggest lead of the game, 93-81, with 3:49 left.
Luc Mbah a Moute stole the ball from Gay, which led to a layup by Jennings to trim the deficit to 95-90 with 57.9 seconds left.
After an airball from Mayo, Tony Allen fouled Ilyasova on a 3-point attempt. He made two of the free throws to trim the margin to 95-92 with 16.5 seconds remaining.
Mayo responded with two free throws for a 97-92 lead with 15.8 seconds to play, but again Memphis committed a silly foul. Gay fouled Ekpe Udoh on another shot from long range, and he made all three free throws to cut the deficit to 97-95 with 12.5 seconds to go.
Mayo clinched the victory with two more free throws for a 99-95 lead with 10.6 seconds to play.
Memphis held a 78-71 lead after three quarters when Mayo hit a 20-foot jumper from the right wing at the buzzer.
The Grizzlies opened the fourth with a 3-pointer from the right corner by Quincy Pondexter for an 81-71 lead with 11:35 left.
Notes: Gilbert Arenas scored four points after sitting out the last three games for Memphis (coach's decision). ... Jennings missed a two-handed dunk on a breakaway, proceeded to get the offensive rebound and then converted a three-point play with 1:02 left in the second quarter. . Milwaukee's Carlos Delfino missed his third game in a row with a groin injury. . Memphis recalled guard Josh Selby from Reno of the D-League earlier in the day. The rookie, who has played in 23 games with the Grizzlies, did not arrive in time.