Cunningham saved the Grizzlies the embarrassment of losing a game in which they owned a 23-point lead in the second half.
The Nuggets were in position to end the huge rally on a positive note when Corey Brewer scored on a slam dunk with 24 seconds to go.
That gave Denver a one-point lead and, after the Grizzlies took a timeout, Gay was called on to try the potential game-winner. That attempt failed, but Cunningham was there to put back the rebound for two of the four points he scored in the game.
Gay had 20 points and helped Memphis build a 34-15 lead after one quarter. Mike Conley and Marc Gasol both scored 16 for the Grizzlies, winners of three in a row and of five out of six.
Brewer made five long-range shots and scored all of 26 points in the second half to lead the Nuggets. It was Denver's eighth loss in nine outings.