Knicks fans vented their fury in historic fashion against Kristaps Porzingis on Thursday, treating him like a Latvian Benedict Arnold from the second he stepped back onto the Manhattan hardwood 20 minutes before tipoff.

All-night boos and rampant “KP sucks!’’ chants ruled this crazed Garden evening and the Knicks responded with a furious performance to beat Porzingis for the second time in a week in a 106-103 thriller against the Mavericks.

The fans rejoiced and chanted, “KP sucks!’’ at the final buzzer for one last rendition as the Knicks players hugged at midcourt as the record ticked up to 3-9.

“I don’t know if it is fair or not — it’s what they know,” Porzingis said of the booing. “It’s what they’ve heard. They’re fans.”

With the score tied, Julius Randle got a key offensive rebound over Porzingis with 20 seconds left that led to a jump ball. The Knicks won the tip, and Marcus Morris (20 points) won it with a step-back 3-pointer from up top with 13.2 seconds left.

Porzingis got to his 20 points after missing his first four shots, but was scoreless in the final period. He finished 7-of-17 from the field with 11 rebounds, three blocks and his ears ringing all night.

“That’s the first time I’ve seen the Garden get like that,’’ Morris said. “I wasn’t surprised, but it was a different level. I felt like we owed it to ourselves to play like that. We’ve been practicing our ass off.”

Another victory over Dallas should really help coach David Fizdale’s cause. Owner James Dolan could be seen applauding and must have been proud that his Knicks fans protested Porzingis’ presence for not wanting to be part of one of the most famous franchises in sports.

Randle (17 points) finally came up huge in the end game. He ran over Porzingis for a driving layup with 1:40 left as the ex-Knick hit the ground but couldn’t get the call in hostile territory. That put the Knicks up 101-99.

“Crowd was amazing from start to finish,’’ Randle said. “You felt the energy the moment you walked into the building, pregame warm-ups. We like Madison Square rocking like that.”

Asked if he was surprised by the venom at Porzingis, Randle said, “It’s New York, man.”

The Knicks are now 2-3 at the Garden — all the losses in ugly blowouts that had the fans jeering.

“We have been on the other side of those sometimes,’’ Fizdale said. “Tonight they showed great appreciation for our effort and that’s the great part of the Garden. It is a big step forward in getting over the hump of playing tight in games in the Garden. I’m hoping was a big step forward in start making this home court and relax.’’

The Knicks closed out the win despite Luka Doncic’s shot-making (33 points) in a triple-double performance (10 rebounds, 11 assists). Doncic led a late third-quarter rally from down 10 points. Porzingis was quiet until the final seconds of the third quarter. He tracked a missed desperation 3 by Doncic and rammed it home just like he used to do in his first three seasons in New York.

The crowd did what it did all night — booed — as Porzingis raised his arms. The score was tied at 87 after three quarters and then Porzingis disappeared.

Playing with five fouls, Frank Ntilikina, the hero in Dallas last Thursday, reappeared. He came up with the biggest hustle play of the final period that had the fans bonkers and then hit two free throws with 3.9 seconds left to ice it.

Fizdale said Ntilikina recently went into his office and told him, “I’m a dog, too,” portending future big play.

And there it was. The Frenchman knocked the ball away from Doncic with 4:20 left and scrambled for the ball in a mad tussle with the Slovenian. A jump ball was called, Ntilikina won the tip and Morris drained a 3-pointer to put the Knicks up four 4:13 left.

When the halftime buzzer sounded, Porzingis took several steps toward the corner where the Knicks file off the court to the locker room before catching himself.

The boos started 20 minutes before tipoff when Dallas players took the court for pregame warm-ups. It was clear then this crowd was bursting with venom for the former Knicks star. Even during timeouts, the fans chanted Porzingis’ initials and booed loudly on every touch.

During player intros, the boos were about as loud as they had been for any opposing player in memory. Porzingis wore a smile during the flogging, but at the end of the night it was just somberness.

“It was pretty loud,’’ Porzingis said. “It sucks that we didn’t get the win. Their fans are really passionate and it was no different tonight.’’