When all else failed — and with the game on the line, most things did – the Rockets came up with a strategy few could have seen coming.

They found an opponent with the ball and the game in his hands who did not know the score.

The Rockets had rallied back from down nine to up five. They had lost the lead and the ball in the final seconds again. They failed to get the rebound when the Knicks missed the shot that could have been, and should have been their last.

But Knicks guard J.R. Smith thought the Knicks were trailing by two, so with 19.9 seconds left, when he could have held for the final shot, he hoisted a 3-pointer. Rockets guard Aaron Brooks pulled in the rebound, was fouled and finally lifted the Rockets a bizarre, 102-100, win that satisfied only in comparison to considerations of the alternative.

“It’s a huge sigh of relief,” said James Harden, who had 37 points a game after scoring a season-high 38. “We found a way. It wasn’t the prettiest win, but at the end of the night, a win is all that matters.”

Far from pretty, the Rockets did all they could to try to give away the game in the closing seconds. The Knicks did more.

Harden had driven the Rockets comeback from down eight to begin the fourth quarter to a five-point lead with 2:25 left. Iman Shumpert, who had already gone five-for-five from the 3-point line, nailed another. Harden turned the ball over with almost a duplication of the turnover in the closing minutes against the Kings on Tuesday. When Francisco Garcia fouled Tyson Chandler on a mid-court jump ball, the Rockets handed the Knicks the free throws to tie the game.