TORONTO — Carmelo Anthony stayed around for the end this time — and that didn’t turn out to be a good thing.

After blasting Toronto, with 29 points midway through the third quarter, Anthony, who had been ejected Friday in Boston, was almost shut out in the final stanza as the Raptors sprinted away down the stretch for a 118-107 victory at Air Canada Centre.

Anthony, seeking redemption after his debacle of a game in Boston, when he was bounced after two quick technicals right before halftime, didn’t notch a point in the fourth quarter Saturday until two meaningless free throws with 22 seconds left.

Anthony finished with 31 points, but didn’t have a field goal in the final period, a recurring pattern in his recent Knicks years. The Knicks dropped to 3-6 — their defense still a train wreck even north of the border.

Somehow, Anthony is staying upbeat as long as the subject is not referee adversary Tony Brothers, who ended his night in Boston. Anthony’s mood uplifted further when he got a locker-room visit from his Olympic teammates, the Raptors’ glittering backcourt of DeMar DeRozan and Kyle Lowry, who ate the Knicks alive in the fourth quarter.

“There was a lot of positive things we did tonight,’’ Anthony said.

Carmelo Anthony fouls DeMar DeRozan.AP

Not really. The Raptors slashed to the basket and burned the Knicks all night, including the fourth quarter. DeRozan scored 33 points and Lowry notched 16, including two key driving layups right through Derrick Rose.

The Knicks’ newest defensive issue, though, is serial fouling. In the back-to-back disaster, the Knicks allowed the Celtics and Raptors 81 free throws. Kristaps Porzingis scored 21 points, but played the final 5:30 with five fouls and not as well.

“I don’t think we took a charge tonight,’’ coach Jeff Hornacek lamented of the Knicks’ inability to draw an offensive foul.

Rose, who bagged 21 points, said the Knicks are getting tin the penalty too early and failing to realize it.

“When they’re in the bonus, close to it, and we got to play safe and under control so we’re not giving up free throws,’’ Rose said.

Though it doesn’t seem serious, Rose suffered a shoulder stinger in the second half.

“I’m more hurt we lost and the way we lost, a game that was so close, so winnable,’’ Rose said. “I love we gave ourselves a chance.’’

Anthony reentered the game in the fourth quarter with 7:03 left, but couldn’t regain his mojo on either end and finished 10-for-21 from the field. Anthony missed all four of his shots in the fourth, including getting blocked on a runner by young Brazilian Lucas Nogueira with 1:09 left and the Knicks down, 109-105.

Rose was blocked on the next possession by Nogueira, the third-year springy forward, as the Raptors’ bench outplayed the Knicks’ forever-changing cast of reserves. On the clincher, DeRozan drove baseline, scored on a layup and got fouled — the three-point play making it 112-105 with 26.8 seconds left.

“They switched and put a bigger guy on me and a smaller guy on KP,’’ Anthony said. “We were trying to find that mismatch.’’

Anthony did nothing to spark the defense. Norm Powell drove the baseline past Anthony for a basket and a 103-101 Raptors lead with 3:54 left.

There was talk in the locker room about adjusting to the recent changes by newly appointed defensive coordinator Kurt Rambis. One big difference is limiting switches on pick-and-rolls.

“It’s not the best to change the defense already in the season,’’ Porzingis said. “Every game we will get better and we’ll be the team everybody expected us to be.’’

The Knicks led 56-53 at halftime behind Anthony’s 20 first-half points. Scoring the final seven points of the half, Anthony finished the half 7-for-13 from the field and 4-for-5 on free throws. He had played just 12 minutes in Friday’s game, so he figured to have fresh legs against the Raptors.