Who knew Andrea Bargnani’s elbow injury would turn into the panacea the ailing Knicks needed.

In what is likely no coincidence, the Knicks steamrolled to their fourth straight rout without the big Italian, using a small-ball alignment that crushed the Cavaliers, 117-86, Thursday night at the Garden.

David Stern, a Knicks fan growing up, made his last appearance at the Garden, and the Knicks put on a show. J.R. Smith dazzled, Carmelo Anthony made more history and rookie Tim Hardaway Jr. created some personal history.

“This is the last game at the Garden where the balls are going to have my name on it,’’ Stern, the commissioner for the last 30 years, said on MSG Network during the conquest.

The Knicks did plenty right with the Stern-inscribed ball as the newly created freewheeling, free-spirited club remained undefeated since Bargnani crashed to the court, injuring his left elbow.

The Heat come to town for Saturday’s Super Bowl Eve showdown and are getting a Knicks team that may be hitting its stride after a season of misery.

Smith had the two highlight plays of the night — driving down the baseline in the first quarter for an over-the-head dunk that had the Knicks bench in a tizzy. He created more buzz in the third quarter, hitting a stepback jumper off a crossover fake that proverbially broke the ankles of Cleveland’s Tristan Thompson, who fell on his back.

“We’re playing Knicks basketball,’’ Raymond Felton said. “Sharing the ball, everybody’s having fun. J.R.’s doing crazy dunks, making people fall. Timmy’s shooting all kinds of 3’s, Melo’s doing his thing. I’m throwing lobs to everybody. It’s fun basketball. I love it.’’

Anthony and Smith combined for 48 points, reminiscent of their 1-2 punch outings of last season. Anthony scored 18 of his 29 points in the first quarter, had one monster driving dunk himself and became the 50th player in NBA history to eclipse 19,000 points.

Hardaway Jr., fresh of being named to the Rookie-Sophomore Game on All-Star weekend, added a career-high 29 points, though 18 of the points came during fourth-quarter garbage time. He was 6 of 12 from three-point land.