MIAMI — Wayne Ellington was not the first, second or probably even the third option on Miami’s final possession.

He was the right option.

Josh Richardson scored 19 points, Ellington capped his 17-point effort with a 3-pointer that sealed the outcome with 4 seconds left, and the Heat beat the Charlotte Hornets 95-91 on Saturday night to snap a two-game slide.

The Heat rallied from a 15-point second-half deficit and atoned for letting a close game slip away against Sacramento on Thursday by holding Charlotte to 13 points in the final quarter.

“The great thing about this league is you have opportunities to learn. You either win or you learn,” Heat coach Erik Spoelstra said. “The other night, that was a tough lesson but we really wanted to make amends for how we finish games defensively.”

Kelly Olynyk scored 16 points and James Johnson added 10 for Miami. The Heat went 4-0 against the Hornets this season, winning by five, six, one and four points.

“They play really hard,” said Hornets guard Kemba Walker, who led all scorers with 30 points. “They are really disciplined and have a lot of heart. That’s why they’re so good.”

Dwight Howard finished with 20 points and 16 rebounds for the Hornets.

“I don’t think we executed in the fourth quarter,” Howard said. “They got some good stops and they were able on their end to make some buckets. We just have to do better.”

Walker had a chance to tie the game when he went to the line down by two with 30 seconds remaining, but made only the first. James Johnson corralled the rebound for Miami, the Heat called time and set up a play to run down the clock.

Charlotte gambled and didn’t foul, hoping Miami wouldn’t make a 3-pointer. The plan backfired when Ellington connected from the top of the arc as the shot clock was expiring.

“Their depth is one of their great strengths,” Charlotte coach Steve Clifford said.

Miami led by as many as 10 late in the first half, but the third quarter brought huge trouble.

Charlotte outscored Miami 27-4 over an eight-minute stretch of that period, the Hornets shooting 10 for 18 from the field in that span while Miami shot 2 for 16.

Charlotte led by 15 twice in the third, only to see that trimmed down to seven by the end of the quarter. Miami clawed within one point on four occasions in the fourth, couldn’t get over the hump on the first three, then finally got the lead back at 92-90 on a three-point play by Richardson with 1:21 left.

“We wanted to make sure we got some stops,” Ellington said. “We dug in and made sure we didn’t have any regrets.”

TIP-INS

Hornets: Howard blocked four shots, the last of those giving him 2,000 in his career. … Charlotte scored 13 points in the fourth, and missed its final five shots. … The Hornets were 28 for 35 from the foul line, compared to Miami’s 11 for 18.

Heat: Ellington now has 150 3s this season, a career-high with 33 games left. … Miami has had a different starting lineup in three consecutive games. … The Heat love weekends — they’re 17-8 on Fridays, Saturdays and Sundays, and 11-13 on all other days of the week. … It was the eighth time the Heat won a game this season when it did not hold a lead going into the fourth quarter.

IN MEMORY

The Heat held a pregame moment of silence for longtime agent Henry Thomas, who died Saturday. Thomas represented several Heat players over the years, including Udonis Haslem, Dwyane Wade, Chris Bosh and Tim Hardaway. “I feel like I lost a dad,” said Haslem, who missed Thursday’s Heat game so he could be at Thomas’ bedside. Heat coach Erik Spoelstra said Thomas was part of the team’s extended family.

LATE SCRATCH

Charlotte was without Michael Carter-Williams, sidelined with a strained left shoulder. His absence provided an opportunity for rookie Malik Monk to get back into the rotation, after playing a total of 10 minutes in the Hornets’ last six games. But Monk missed all four of his shots in seven scoreless first-half minutes.

UP NEXT

Hornets: Visit Atlanta on Monday, continuing a three-game trip.

Heat: Visit Dallas on Monday, starting a four-game road swing.