Updated

Ray Allen continued his torrid pace and helped the Miami Heat avoid another home loss.

Allen scored 18 points as the Heat defeated the Memphis Grizzles 91-86 on Friday night and avoided losing at home for the third time in their last four games.

Allen is averaging 18 points per game in Miami's past five games.

"It's really just team oriented," Allen said. "When we play well, we move the ball around. There's no telling who's going to be the recipient. Whether it's offensively or defensively, somebody's got to make plays out there.

"On any given night, based on who we play, it could be anybody."

Miami rallied from an 84-77 deficit with 4:08 remaining and scored 11 unanswered points. Allen's 3-pointer with 3:27 remaining began the comeback and Dwyane Wade's jumper with 1:32 left tied it at 84. Wade's two free throws with 1:04 left gave the Heat their first lead since early in the third quarter.

"We had to make plays on both ends in the fourth quarter and manage the game with intensity and the right plays," Miami coach Erik Spoelstra said.

After Mike Miller missed a 3-point attempt with 51 seconds remaining for the Grizzlies, LeBron James' jumper with 24 seconds left capped the Heat's late run for an 88-84 advantage.

James finished with 15 points, and Wade and Mario Chalmers scored 14 points each for the Heat. James also had seven assists and six rebounds.

"It was one of those grind-out, playoff-type games," said James, who sat out Miami's game at Boston on Wednesday because of back spasms. "No matter what happens, you just have to try to make plays to help you win. Myself, and D-Wade and the rest of the guys made plays down the stretch."

Zach Randolph scored 25 points and had 14 rebounds for the Grizzlies. Marc Gasol finished with 14 points, but left because of a sprained ankle midway through the third quarter and didn't return.

"We turned the basketball over way too much," Memphis coach David Joerger said of his team's six fourth-quarter turnovers. "They've got good players that made big plays."

Chalmers scored eight points during a 16-4 run that closed the third quarter and helped Miami erase a 12-point gap. Chris Andersen's tip-in at the buzzer ended the surge and tied it at 68.

"We got kind of stagnant toward the end," Randolph said. "Overall, we played good. We just couldn't make shots toward the end."

The Grizzlies opened the second half on an 11-2 spurt behind two baskets each from Gasol and Randolph. But Gasol injured his left ankle after colliding with Chris Bosh's left foot. Gasol left for the dressing room with 6:20 remaining and didn't return.

"He got hurt and then the game kind of changed," Randolph said.

Mike Conley's three-point play with 5:13 left in the third period gave the Grizzlies their first double-digit lead at 62-52.

"The Memphis Grizzlies are a very good team that's playing well and we just had to find a way in any way possible, and it all happened on the defensive end of the floor for us," Wade said.

Miami rallied from two nine-point deficits early in the second quarter and finished the period on a 14-7 spurt. James' jumper with 37 seconds remaining gave the Heat a 45-43 lead at halftime.

Miller's first basket against his former teammates was a 3-pointer that increased the Grizzlies' lead to 29-29 with 9:46 remaining in the second quarter. Miller received a huge ovation from fans and hugs from his former teammates when he was presented with the Heat's championship ring before the game. He was not available after the game.

"We hate that he's not around here still," James said. "It's great to see our fans and our franchise pay respect to a guy who helped us win two championships."

NOTES: James didn't reach double-digits in scoring until his jumper 1:03 into the fourth quarter. ... Randolph had his 398th career double-double. ... Tennis star Roger Federer, in Miami for the Sony Open, attended the game and hit several tennis balls into the stands during a timeout.