DETROIT — The Knicks have fired their head coach, fired their president and traded their best player for future assets.

Only Knicks owner James Dolan could intercept a season so resolutely.

Despite it all, the Knicks posted their season’s first four-game winning streak, and first since December 2017, when they took out the Pistons, 95-92, on Saturday at Little Caesars Arena with more clutchness down the stretch.

Lo and behold, the Knicks (17-36) moved five games out of the eighth seed — and matched last season’s win total.

“We talked about how resilient this group has been,’’ said interim coach Mike Miller, whose team is 13-18 since he took over. “To have some excitement and success we’re having, they’re staying together.’’

It was the Knicks’ first win in Motown since 2015 and first triumph in the Pistons’ 3-year-old downtown palace.

Julius Randle drives to the basket during the Knicks' 95-92 win over the Pistons on Saturday.
Julius Randle drives to the basket during the Knicks’ 95-92 win over the Pistons on Saturday.NBAE via Getty Images

Backup shooting guard Wayne Ellington, who before the game said he may want a buyout, poured in 17 points off the bench. His 3-pointer with 4:43 left tied the score at 84.

The Knicks’ offense had trouble making up for the loss of Marcus Morris, traded Thursday, but Julius Randle came up big at the end after a rough shooting night.

Randle shot 7-of-17, including a 3-point airball midway through the fourth quarter, but finished with 17 points. He came up big in the final minutes, capped by a backbreaking lefty hook with 13.5 seconds left, though replays showed he bashed Detroit’s Thon Maker in the mouth, knocking out three of his teeth. Pistons coach Dwane Casey asked for a review too late after Maker tumbled to the court and needed medical attention.

“Just trying to use my speed and strength against two long guys in [Christian] Wood and [Thon] Maker to get to the basket and I hit a shot,’’ Randle said.

Randle also made a hustling save of an out of-bounds ball with 36 seconds left on a missed Ellington jumper.

“We’re doing it different ways down the stretches,’’ Randle said. “Earlier in the year, we had trouble closing games like this. When things went wrong, it snowballed. But every guy in this locker room is about winning and it’s showing.’’

Rookie RJ Barrett, in his second game back from an ankle sprain and first in the starting lineup, was off kilter. After missing his first five shots, Barrett finished with three points on 1-of-8 shooting and was a minus-15.

Center Mitchell Robinson made an impact on defense with three blocks, one steal and a key offensive rebound with 20 seconds to go. Elfrid Payton scored 10 points, had six assists and nine rebounds, making a key runner in the lane with 1:30 left, putting the Knicks up by two.

A solid rebounding team all season, the Knicks battered the Andre Drummond-less Pistons on the boards 47-28.

Reggie Bullock’s two free throws with 7.3 seconds gave the Knicks a three-point lead, and Detroit’s Reggie Jackson bricked a 3-pointer in the final seconds.

Miller didn’t use newcomer Maurice Harkless because he didn’t know enough plays and was travel-weary.

Morris did not play for the Clippers either on Saturday, though he didn’t sound so heartbroken. The Clippers had offered him a free-agent contract in July.

“Obviously last summer things didn’t go the way I thought it would, but we’re here now, $15 million richer,’’ Morris told reporters in Los Angeles.