MIAMI — Gordon Hayward scored 25 points, Kyrie Irving added 23 and the Boston Celtics pulled away in the final minutes to beat the Miami Heat 112-102 on Wednesday night.

Al Horford scored 21 and Jayson Tatum scored nine of his 16 points in the fourth quarter for the Celtics, who went on a 10-2 run over a decisive three-minute late stretch. That little burst turned a two-point lead into a 10-point edge, and Boston finished off its second win over Miami in a three-night span — dealing the Heat’s playoff hopes a serious blow.

Aron Baynes had 10 points and 10 rebounds for Boston, which remained tied with Indiana for the fourth-best record in the Eastern Conference. Those teams meet in Indianapolis on Friday, with the No. 4 spot in the East race at stake.

Dion Waiters scored 21 points for Miami, which was potentially playing the next-to-last home game of Dwyane Wade’s career. Hassan Whiteside came off the bench to finish with 18 points and 15 rebounds for Miami, and Wade scored 17 for the Heat.

Detroit and Brooklyn also lost on Wednesday, meaning the race for the No. 6 spot in the East is even more muddled than it was entering the night. Detroit is sixth at 39-39, Brooklyn and Orlando (which beat New York) are 39-40, and the Heat fell to ninth at 38-40 – a half-game out of eighth, a game out of sixth, but running out of time.

Boston led for the overwhelming majority of the first three quarters – the Heat led for 5:36 of those 36 minutes, yet the Celtics never really seemed in full control of the game until the final moments.

Little spurts were enough.

Dragic tied the game for the sixth time with a pair of free throws to open the fourth quarter, and Boston scored the next six to go up 89-83 with 8:55 remaining. The Celtics held the lead the rest of the way.

NOTES: Boston, which jumped to a 17-2 lead over Miami on Monday, started this game on a 9-0 run. … Jaylen Brown missed his second consecutive game with back spasms, and Marcus Morris was out with a sore left knee. … Irving has played in 11 games at Miami; his Cleveland teams went 0-7 on the Heat home floor, and his Celtics teams are 2-2.