Jerryd Bayless scored a season-high 21 points to help the Grizzlies win without point guard Mike Conley, out with a sprained left ankle.
The Grizzlies rallied from 17 down to take control late in the fourth. Bayless missed a jumper, Gay grabbed the rebound and made it 101-100 on a bucket with 13.3 seconds left. Philadelphia's Thaddeus Young missed a short attempt in front of the basket and the Grizzlies grabbed the rebound.
Gay was fouled and made both free throws for a three-point cushion.
Nick Young couldn't get the tying shot off at the buzzer for the Sixers.