BOSTON — The Cleveland Cavaliers had already erased a 22-point deficit when LeBron James grabbed a rebound with 10 seconds left and raced down the court.

Two to tie. Three to win.

James tried for the 3.

And missed.

James scored 20 of his 42 points in the fourth quarter, but he missed two free throws in the final 16 seconds and a pair of 3-point attempts as the Boston Celtics withstood Cleveland’s charge for a 117-113 victory Sunday.

“It’s tough to question anything he does,” Celtics Coach Doc Rivers said. “It felt like he scored their last 60 points in a row at one point. And who didn’t think that was going in when he shot it?”

Ray Allen scored a season-high 33 points, hitting his sixth 3-pointer to give the Celtics a four-point lead with 48 seconds left, and Rajon Rondo scored 16 with 14 assists to help Boston snap a three-game home losing streak.

Kevin Garnett scored 19 points and Paul Pierce had 16.

The Celtics and Cavaliers finished the season series tied, 2-2.

A game that seemed like it might be a pleasant distraction from Sunday night’s Red Sox opener against the rival New York Yankees turned into a full-scale playoff preview, a technical foul-filled, down-to-the-wire rumble between one of the NBA’s top stars and one of its greatest teams.

Six technical fouls were handed out, two to Cavs Coach Mike Brown, who was ejected. James got one and was spared another when he lingered in the Celtics’ huddle during a timeout to exchange words with Tony Allen.

“We don’t like them. They don’t like us. So I wasn’t surprised at all,” James said, citing the seven-game playoff series Boston won in 2008 on its way to its 17th NBA title. “It comes from them wanting to be really great, them winning the championship, us wanting to win the championship and having to come through Boston to try to win it.

“The competition – that’s what’s good about this game.”

Garnett, who was fined $25,000 for comments about the officials’ treatment of Kevin Durant last week, also had words with James but declined to elaborate on what was said.

“Nothing in particular that I want to share or that the NBA wants me to share,” Garnett said. “Y’all are trying to cost me another ($25,000).”

The Cavs scored 23 of the first 28 points in the fourth quarter to erase 17-point deficit, taking their first lead at 104-103 with 2:58 left. James missed 1 of 2 free throws with 16 seconds to go, then did it again with 11 seconds to play before misfiring on 3-point attempt with 3.2 seconds left when Antawn Jamison was open for a 2-pointer that would have tied it.

“LeBron is a great player and we’re lucky to have him,” Brown said. “Guys, in order to be great, have to have a lot of confidence. You have to have confidence to take big shots, and at times take some risks. If he felt like he had a clean look at it, fire away.”

James was 0 for 9 from 3-point range, including a meaningless, unguarded shot at the final buzzer that bounced off the rim.

Afterward, he and Garnett exchanged dirty looks.

“It’s two teams that I don’t think love each other, I can say that, and there’s two teams that want to beat each other,” Rivers said.

“Early on, we were having our way, so they got frustrated. And later they were having their way, so we got frustrated.”