BOSTON — The Dallas Mavericks didn’t look ready at the beginning of the game.

They sure made it look easy in the final quarter.

Dirk Nowitzki scored 23 points, Wesley Matthews had 18 and the Mavericks erased an 18-point, first-half deficit to beat the Boston Celtics 106-102 on Wednesday night for their fifth straight victory.

“I thought their energy was great there in the first quarter,” Nowitzki said of Boston’s scrappy backcourt. “They were all over us. I don’t think we were ready for how intense they play. We did a great job closing it out there in the fourth. That was a fun game. Everybody was sharing the ball and making some key shots.”

Zaza Pachulia had 14 points and 12 rebounds for the Mavericks. Deron Williams added 16 points, including consecutive key baskets.

But it came down to a crucial steal to seal it.

The Celtics closed to 104-102 and had a chance to tie or take the lead, but Raymond Felton stole the ball from Isaiah Thomas in the closing seconds after Felton missed two free throws that would have secured the win.

“I’ve just got to be cautious of that and learn from that mistake,” Thomas said.

Williams then nailed two free throws, making him perfect on 30 attempts this season.

“I can’t say enough about the play Raymond made there at the end after missing the two free throws,” Dallas Coach Rick Carlisle said. “He sprinted back and he got a deflection.”

Boston Coach Brad Stevens knew his team wasted an opportunity.

“Well, Felton was clearly behind him, and he had it going in that direction,” Stevens said. “We looked like we might even have an advantage break at one point.”

Thomas led Boston with 19 points. Jared Sullinger had 18 points and 12 rebounds, and Avery Bradley scored 18 as the Celtics had their three-game winning streak snapped.

Dallas trailed 89-82 after Thomas’ jumper with just under 8 minutes to play before going on a 14-2 run.

Williams’ 3-pointer from the left corner gave the Mavericks their first lead, 94-91 with 4:18 to play. He followed with a short jumper after Boston turned the ball over with a backcourt violation.

Trailing from the game’s opening basket, the Mavericks erased a nine-point halftime deficit, tying it twice in the third quarter, but Boston closed with an 11-4 spree to lead 78-70 after three. Kelly Olynyk and Bradley each had a 3-pointer from the left corner during the run.

Coming off impressive double-digit road wins at Oklahoma City and Houston, Boston opened an 18-point edge late in the opening quarter, but had it sliced to 54-45 at halftime because of Dallas’ hot shooting.

The Mavericks shot 64.7 percent (11 of 17) in the second after starting the game ice cold.