Jason Terry took over late in Game 4. (Jessica Rinaldi/Reuters)

The Boston Celtics needed to be staring squarely at elimination from the NBA playoffs in order to be at their gut-it-out best.

Paul Pierce and Kevin Garnett — the last healthy holdovers from Boston’s 2008 championship team — as well as newcomer Jason Terry made sure the Celtics extended their season for a few more days with a gutsy 97-90 overtime victory over the New York Knicks on Sunday at TD Garden.

“When your leaders are KG, Pierce and myself, we have too much pride,” Terry said. “Getting swept is something that no man that’s been in this league that long wants to do.”

Desperation contributed to Garnett to elevating for a rare alley-oop dunk and grabbing almost every available rebound, for Pierce driving baseline around Jason Kidd for an emphatic jam and Terry shooting as the team expected when it signed him as a free agent last summer.

The Celtics, who cut their deficit in the best-of-seven first-round series to three games to one, also needed the Knicks’ best offensive weapon to stay off-target and their second-best option to be serving a suspension. It still almost wasn’t enough after Boston squandered a 20-point third-quarter lead.

Pierce led the Celtics with 29 points and former Georgetown star Jeff Green scored 26. But Terry, a 14-year veteran who won a championship with Dallas two years ago, scored Boston’s final nine points to finish with 18 and help force Game 5 on Wednesday at Madison Square Garden.

“I already called my friends in New York telling them I’d be there for dinner,” Pierce said.

The four-game sweep was there for the Knicks, but as Carmelo Anthony kept missing, the Celtics kept pushing — even when Brandon Bass fouled out late in regulation after he played superb defense on Anthony, and even with Green going scoreless over the game’s final 9 minutes 47 seconds.

“We wanted to survive,” Garnett said after scoring 13 points with a game-high 17 rebounds. “This is the position we put ourselves in. To continue to play, we’ve got to continue to win. That’s what it’s all about.”

Terry, whom Celtics Coach Doc Rivers calls a “sunshine-bringer” for his consistently positive attitude, made a huge contribution before the game even tipped off. He was on the receiving end of J.R. Smith’s flagrant fourth-quarter elbow in Game 3, leading to the ejection of Smith, the NBA’s sixth man of the year, and his suspension for Game 4.

Then with the game tied at 88 in overtime, Terry buried a pull-up three-pointer. Anthony responded with a tough fadeaway, but Terry made another jumper to give the Celtics a 93-90 lead with 92 seconds remaining.

After Anthony missed a three-pointer, Terry added two free throws and capped the scoring when Garnett rebounded another Anthony miss and tossed the ball downcourt. Terry scooted toward the hoop, made the layup, then brought out his signature move, leaning over spreading his arms and gliding down the floor like a jet.

“It’s been in the hangar for a while,” Terry said, “so I had to let that out.”

Terry’s big-shot celebration wasn’t all that finally made an appearance for Boston on Sunday. The Celtics broke the 80-point barrier for the first time in the series and managed to keep Anthony and the Knicks from taking over in the final minutes.

“We knew they were going to come out like that. They were fighting for dear life,” Anthony said of the Celtics. “I was trying to win the basketball game. It would’ve been a great feeling to close it out here in Boston.”

Anthony led all players with 32 points but missed 25 of 35 shots with Bass and Green defending him for much of the game. After Bass fouled out, Green and Pierce helped limit Anthony to four points on 1-of-4 shooting in overtime.

“Those are shots I’ve been taking the whole series. They weren’t falling,” said Anthony, who also missed all seven of his three-point attempts. “My mother always said, ‘There’ll be days like this.’ We’ll take it for what it’s worth, put this one behind us and get ready for Wednesday.”

Knicks point guard Raymond Felton scored 27 points, including 13 during a 26-9 run that brought his team within 68-65 entering the fourth quarter. Felton hit another pull-up jumper to give the Knicks an 84-82 lead with 1:18 left in regulation, but the Celtics responded with Pierce finding Garnett in the corner for a long jumper along the right baseline.

“There was a lot of pride,” Pierce said. “Every time I look up there, you feel it, you see it, you hear it. There’s so much pride when you look around, the banners, the crowd and everything going on with the Boston Celtics’ history.”