Frustrating end: Carmelo Anthony, who scored 12 of his 39 points in the fourth quarter, couldn’t keep the Knicks from blowing a 15-point lead over the final 12 minutes.Getty Images

DENIED: Tyson Chandler gets his shot stuffed by the Pacers’ Roy Hibbert during the Knicks’ 112-104 loss in Indy last night. (AP)

Frustrating end: Carmelo Anthony, who scored 12 of his 39 points in the fourth quarter, couldn’t keep the Knicks from blowing a 15-point lead over the final 12 minutes. (
)

INDIANAPOLIS — In the final seconds, after the Knicks had already disgraced themselves in the fourth quarter, J.R. Smith ran downcourt with Leandro Barbosa, bumping him along the way.

After Carmelo Anthony scored on a putback, Smith and Barbosa got entangled and Smith threw him to the court, getting ejected with 10.7 seconds left — the final exclamation mark to the Knicks’ fourth-quarter meltdown.

The game was over by then as the Knicks were destroyed 40-17 in the fourth quarter in blowing a 17-point late third-quarter lead and suffering a 112-104 loss to the Pacers Tuesday night at Bankers Life Field House.

If they miss out on a playoff berth, they can remember this horrible collapse when they had the game won despite missing the injured Amar’e Stoudemire and Jeremy Lin for a fifth straight contest.

Interim Mike Woodson called Smith’s display “unprofessional,” and really he could have been talking about the entire team over the final 13 minutes, when the Knicks got outworked by the Pacers.

“Forty points in the fourth quarter is too much,’’ Anthony said. “They were able to get stops, rebounds and just outworked us. We kind of got lax going into the fourth quarter and they ran away with it. They wanted it more.

“I think we got a little bit complacent being up 17. It was just unfortunate. We can’t have that.”

Anthony finished with a season-high 39 points, dazzled for three quarters in his new position at power forward, but couldn’t hit the big shot late, missing two key 3-pointers in the final minute. For the Pacers, Danny Granger scored 14 of his 27 points in the last quarter.

Anthony was hardly why they lost. The Knicks got complacent and the Pacers outhustled them, namely reserve Lou Amundson, who ferociously attacked the offensive glass. The Knicks, who play in Orlando tomorrow, fell to 27-27. They lead the Bucks for the final playoffs spot by just 1 ¹/₂ games.

“It got ugly for us,’’ said Davis, who had an uneven night with 2-of-8 shooting and three assists in 29:12. “This is just a bad loss. We had this game. We had everything going right for us. It should light a fire under us.’’

The Pacers bludgeoned the Knicks with a 31-6 run after Woodson’s team went up 87-70 with 55 seconds left in the third quarter. The Pacers started the fourth on a 16-2 run as the Knicks missed 13 of their first 16 shots.

Davis was benched in the final 1:10 and Iman Shumpert closed out the game at point guard. Nothing worked. The Knicks (27-27) got too happy with their lead, perhaps with the knowledge they had beaten them two straight times in March.

“We stopped moving the ball, we stopped scrambling,’’ Smith said. “They came out and played harder than we did. We got to do a better job stepping on their neck.’’

On the play that triggered Smith’s ejection, he inbounded the ball in the backcourt for Tyson Chandler, but Paul George intercepted and dunked. Smith claimed Barbosa and he were in a tug-of-war all game and the referees didn’t see Barbosa’s chippiness.

Woodson said he regretted keeping Smith in during their crumble. Starting shooting guard Landry Fields had emerged from his slump with a terrific 12-point first half. But Fields was benched with 4:30 left in the third and played just 45 seconds of the fourth quarter. Fields said afterward he was not hurt.

“It was a tug-of-war,’’ said Smith, who came to the Knicks with a tough-guy rep. “The refs didn’t see it. They only saw the end of it. It happens. It’s just the frustration of the game. Bumping and the grinding, he was going at me, I was going at him. It was going on the whole game. Nobody really paid attention to it. I just got a little fed up with it.’’

Owner James Dolan signed Smith in late February, and the Knicks have to take the good and the bad.

“It’s how you play with our emotions. You got to control that,” Anthony said.

Woodson said he will be in Smith’s ear today.

“I’ll sit down and talk to J.R. and tell him you got to be a little more professional,’’ he said. “Maybe I should’ve pulled him. I didn’t. But I’ll talk to him because that was unprofessional I think.’’

Anthony was spectacular for three quarters, seemingly as pumped up as he has been all season, playing physically on defense and ferociously on offense, getting to the rim against Tyler Hansbrough.

But all that fire disappeared in the fourth quarter and Anthony missed two open looks late.

“They were in there and came out — they both felt good,’’ he said.

Defense had been a staple of Woodson’s reign before Tuesday night.

“The fourth quarter had been good to us from a defensive standpoint,’’ said Woodson, who fell to 9-3. “You can’t give up 40 points in the fourth quarter.’’

On one illustrative possession, Amundson notched two offensive rebounds on one possession with the Pacers clinging to a 98-93 lead. That allowed George to drive to the basket and get fouled.

Clearly the Pacers weren’t happy with the Knicks’ hot-dogging, particularly Steve Novak’s championship-belt maneuver after he hit a trey at the first-quarter buzzer. In the fourth, Granger nailed a tiebreaking 3-pointer to put the Pacers up 94-91 and did the belt move, and the Knicks were on their way to being knocked out.