CHARLOTTE, North Carolina — The Boston Celtics didn’t keep to the script they meant to follow on Saturday night, but the ending was exactly what they wanted.

The Celtics eventually prevailed over the Charlotte Hornets, 121-114, but not before blowing a 19-point third-quarter lead and then having to rally from a seven-point deficit in the fourth.

Isaiah Thomas led the way with 32 points, including seven straight points when the Celtics reclaimed control. Afterward, he had mixed emotions about the performance.

“As long as we got the win, that’s what really matters,” Thomas said. “It’s a little frustrating, but Coach [Brad Stevens] even said in the huddle, ‘Don’t think there’s not going to be playoff games like this, just figure out a way to win.’ At this point of the season, it’s all about figuring out a way to win.

“We’ve got to be better at when we do have leads and sustain the other team’s runs and play the right way. I think that’s a problem we have right now. So we’ve just got to keep working at it.”

Stevens said he liked the Celtics’ resolve after they blew the big lead and had to come from behind. Boston led 71-54 at halftime and 75-56 in the third.

“You want every 17-point lead to stay that way, but very rarely does it,” Stevens said. “It’s a long game. People go on runs. Usually you can stem the tide once it gets to a certain point, and we weren’t able to do that. We’re going to face adversity throughout the next few weeks and we have to be able to respond, so that was good.”

The win moved the Celtics (51-29) back to within one-half game of Cleveland for first place in the Eastern Conference, although the Cavaliers have already earned the tiebreaker advantage. The win also snapped a two-game losing streak, and gave the Celtics a four-game sweep over the Hornets this season.

The Celtics also got 16 points from Al Horford, 15 points each from Avery Bradley and Jae Crowder, 13 points and 11 rebounds from Kelly Olynyk, and 10 points from Jaylen Brown.

They shot 51.7 percent from the field and made 17 3-pointers. Eleven of those triples came in the first half.

Ultimately, the Celtics found themselves trailing 104-97 after Charlotte’s Marvin Williams hit a 3-pointer with 6:38 remaining. The Celtics responded with nine straight points to regain the lead, and then Thomas took control down the stretch. He on a drive, hit two free throws, then sank a 3-pointer to put the Celtics up 116-111 with 1:22 remaining.

“That’s hard when you’ve had the lead and they take it all the way up to seven,” Stevens said. “To come back and win it, it shows a lot of resolve.”

The Hornets (36-44) were officially eliminated from the Eastern Conference playoff race with the loss. They won 48 games last season and figured to be even better this season, so this team will go down as huge underachievers.

“The story of our season has been we haven’t been able to defend in the fourth quarter,” Hornets coach Steve Clifford said. “Tonight again, they had 29 in the fourth, so that part of it has some symbolism.”

Clifford was ejected after picking up two technical fouls in the second quarter. The second came with 1:09 remaining in the half, with Boston leading 62-51. It appeared that Clifford was determined to get tossed from the moment he got his first technical with 3:20 left in the half, but he said otherwise.

“The first thing I had to do was apologize to the team for doing that,” Clifford said. “That wasn’t my intention.”

Nicolas Batum led the Hornets with 31 points and eight rebounds. Kemba Walker scored 23, Jeremy Lamb added 17, and Cody Zeller had 12 points and nine rebounds.

“We’re disappointed for sure,” Batum said. “We wanted to be in a playoff spot like we did last year, but we weren’t far away. We were right there with all those teams. We’re a playoff team. We know that. We didn’t make it this year.”

NOTES: The Celtics won 104-98 in Charlotte on Oct. 29, 96-88 in Boston on Dec. 16, and 108-98 in Boston on Jan. 16. The Celtics have won six straight in the series. … The Celtics were without F Amir Johnson (illness) and F James Young (illness). … The Hornets were without F Johnny O’Bryant (ankle) and G Marco Belinelli (finger). … The Hornets were 29 of 32 from the free-throw line, to Boston’s 14 of 17. … Celtics F Kelly Olynyk got just his sixth start of the season and responded with a double-double before fouling out. Coach Brad Stevens quipped that Olynyk was just four fouls away from a triple-double. … Celtics G Isaiah Thomas will likely end the season with the second-highest scoring average in franchise history. He came into the game averaging 29.1, just a fraction below Larry Bird’s franchise record of 29.9 in 1987-88. … The Celtics will return home to face Brooklyn on Monday and then will close out the regular season at home against Milwaukee on Wednesday. … The Hornets will close out the season with games at Milwaukee on Monday and at Atlanta on Tuesday.