SALT LAKE CITY (AP) -- LeBron James once scored 51 points against the Utah Jazz, and needed 50 on Monday night to become the youngest player to reach 20,000 for his career.
He almost got there.
James scored 32 for the Miami Heat, but the Jazz held on after nearly blowing a 21-point lead and won 104-97.
"We're trying to learn how to push a lead from 20 to 30 and close teams out, but we haven't been able to do that for whatever reason," said Jazz guard Gordon Hayward, who finished with 22 points on 8-of-13 shooting. "We need to be able to keep our foot on the gas and not be hesitant."
Dwyane Wade, who finished with 11 points on 5 of 11 shooting, did not get off the bench in the fourth quarter for the Heat.
"I don't know," Wade said. "I just always stay ready."
Miami pulled within two points on a free throw by Joel Anthony with 3:13 left, but James was called for goaltending and an offensive foul on back-to-back possessions, then missed a 3-pointer with the Heat trailing by six with 2:19 remaining.
His floater in the lane still had Miami within five with 1:25 left, but Hayward hit a 14-foot fadeaway shot with 40 seconds to seal it.
The basket came after yet another offensive rebound by Paul Millsap to give the Jazz a 19-0 edge on second-chance points.
"LeBron still got his numbers, so we didn't do much to control him. But we took everybody else out of the game and kept them from getting theirs," said Millsap, who finished with 17 points, nine rebounds and two steals.
"They got no second-chance points, so that was big for us. That means we finished the defensive possessions with a rebound and that let us get out and run a little bit. We controlled the tempo."
Al Jefferson also turned in a big game after being held to just six points in a 105-89 loss in Miami on Dec. 22. He had 10 after the first quarter and finished with a team-high 23 on 8-of-14 shooting, with 11 rebounds.
He also made 4 of 4 free throws down the stretch.
"The game was too close to be nervous," Jefferson said. "I knew they would make their run, they are too good. But when we were only up two, I didn't panic. I knew we had them in the penalty, so we just had to be aggressive."
It helped that Hayward got a shot to fall in a quarter that saw Utah make just four of 19 overall.
"They caused some trouble. They're a good defensive team and we were indecisive and hesitant," Hayward said of the fourth.
Early on, the Heat came out hot, and led 16-8 only to be outscored 37-13 over the next 11 minutes.
The Jazz turned the game with strong play from their reserves, solid defense, hot shooting and second effort. DeMarre Carroll come off the bench to score seven points in four minutes and Jefferson shot 5 of 8 to give the Jazz a 30-25 lead after the first quarter.
Utah opened the second on a 15-4 run to bump its lead to 45-29. The Jazz hit 12 of 15 shots (3 of 4 from beyond the arc) in the quarter (80 percent) and took a 59-44 lead into the break.
Hayward scored 12 points on 5-of-6 shooting in the second quarter, helping the Jazz stretch their lead to 17. Utah's bench dominated, outscoring Miami 33-5 in the first half. The Heat shot 50 percent in the opening two quarters, but couldn't match the 67.6 percent the Jazz were shooting (25 of 37) or their 3-point effort (5 of 7).
"It was low energy," James said of falling behind by so many. "Low energy against a team like this on their floor with this amazing crowd, can't play with low energy."
Heading into Monday's game, James was averaging 30.4 points against the Jazz over his career -- his highest against any opponent.
He hit his first three shots and had 11 points after the first and 20 at halftime on 8-of-11 shooting. But he clearly was frustrated as Miami struggled with Utah's size, aggressiveness and hot shooting. He slapped his hands as if to say "Let's go" after he scored a short jumper that pulled the Heat within 48-33. His dunk after an ugly missed dunk got Miami within 56-42. But Jamaal Tinsley, starting in place of point guard Mo Williams, countered with Utah's fifth 3-pointer of the half.
Asked if he felt alone on the floor, James said he was just trying to make plays.
Carroll and Marvin Williams spent much of the night trying to contain him, along with Millsap.
"Sometimes our guys got beat, but there was another guy right there to confront the ball handler. We helped each other," Williams said. "Paul Millsap is tough with a capital T, man. Paul is so mellow, but he is also tough and he doesn't back down from anybody."
Utah held a 40-23 advantage on the boards, and 47-26 edge in bench scoring.
Chris Bosh added 16 points for Miami and reserve Rashard Lewis had 13.
Heat coach Erik Spoelstra was pleased to see the big rally, but said everyone in the locker room needs to give more for a team that has won just five of its last 11 and has two more games on this six-game road trip.
While James could reach the historic plateau Wednesday at Golden State, the Jazz now have some time to rest. Plus, they have 11 of their next 14 at home where they improved to 12-4.
Randy Foye said the win shows Utah (21-19) can beat anyone "no matter if it's the defending champ or the worst team in the league.
"It's just a big win for us."
NOTES: Ray Allen entered the game eight points shy from tying Robert Parish (23,334) for 21st on the NBA's career scoring list. He finished with 10. . Referees had security remove a fan who was heckling Wade. . The Jazz had a season-high 20 assists in the first half. . Jefferson recorded his 19th double-double of the season.