Miracles do happen.

Carmelo Anthony made a grand return, but Iman Shumpert became the irreplaceable sidekick with the kind of monster night the Knicks have needed all season.

Shumpert tapped in Anthony’s missed corner 3-pointer for the go-ahead points with 23.4 seconds left to cap a brilliant evening with a career-high 27 points as the Knicks started the new year in style by shocking the Spurs, 105-101, at AT&T Center.

Anthony finished with 27 points, 12 rebounds and four assists after missing three games with a sprained left ankle. Though he petered out in the fourth quarter, he hit the game-sealing free throws with 7.2 seconds left.

But it was Shumpert who won the game with a giant 3-pointer, the tip-in and collecting a key loose ball. He outdueled Italian sharpshooter Marco Belinelli, who nearly beat the Knicks single-handedly with a season-high 32 points on 12-of-16 shooting.

Shumpert nailed 10-of-13 shots and made six-of-eight 3-pointers, all while defending Spurs point guard Tony Parker — with the Knicks uncomfortable using Beno Udrih.

“He saved us. He saved the day,” Anthony said. “Back to the old Shump we loved. If he plays like he did, we’re a tough team.”

The Knicks had blown all of a nine-point lead in the final five minutes. Tim Duncan put the Spurs up by two and the Knicks looked to be collapsing in full.

But Shumpert collected a loose ball after a scramble, got it back on a feed from J.R. Smith and fired in a left-wing trey with 39.1 seconds left, putting the Knicks up 101-98.

It has been a trying season for Shumpert, who has heard his name bandied in trade talks. But recently owner James Dolan told the team there will be no deals.