NEW YORK -- James Harden's most productive scoring night of the season was almost overshadowed by a play he made late in Thursday's game.
The Rockets guard poured in a season-high 36 points in Houston's 109-106 win over the New York Knicks at Madison Square Garden, but his foul on Carmelo Anthony with five seconds left nearly cost his team the win.
Anthony, who scored an NBA-season-high 45 points, just missed a potential four-point play when Harden fouled him intentionally behind the arc with Houston leading by three.
With Harden draped all over him, Anthony threw the ball up and it went in, but the referees ruled the shot came after Harden fouled him. Anthony made both free throws, but Harden responded with two free throws to increase the Rockets' lead to 109-106 with 2.9 seconds left.
"He lost the ball up high at first, and that's when I fouled him initially," Harden said. "He finally gathered himself and shot it, but I knew (it was not a shooting foul)."
Knicks coach Mike Woodson unsuccessfully attempted to have the officials review the play to see if Anthony was in the act of shooting.
"I am up there screaming to try and get it reviewed," Woodson said. "I thought it was close enough to have that play reviewed, but they never entertained it."
Jeremy Lin scored 21 points in his second game back to Madison Square Garden since his "Linsanity" days two seasons ago with the Knicks.
The win was the 16th in 17 games for the Rockets (6-4) against the Knicks. New York (3-5) dropped its third consecutive home game.
Lin scored nine points in the fourth quarter for his third solid game in a row. He scored 31 points against the Toronto Raptors on Monday and 34 against the Philadelphia 76ers on Wednesday.
"I was just having fun out there," Lin said. "You know, I miss playing at the Garden. It's great to come back here once a year and play.
"The fans are great and the atmosphere is incredible."
Harden, who missed the Rockets' overtime loss in Philadelphia on Wednesday due to a bruised left foot, scored seven consecutive points to give Houston a nine-point lead with 3:51 left. He scored 12 points in the fourth quarter.
New York center Andrea Bargnani hit a 3-pointer with six minutes to play to tie the score at 91, but the Rockets pulled away with an 11-2 run to take a 102-93 lead with 3:59 left. Harden scored seven points during the spurt.
Houston center Dwight Howard was held to seven points, his lowest output of the season. He did, however, contribute 15 rebounds and four blocked shots.
Howard had 41 points and 39 rebounds in his previous two games.
The score was level with 11:26 left before Houston used an 8-0 run to move ahead 83-75 with 10:03 to play. Lin scored five points during the burst.
Bargnani's second 3-pointer of the game closed the Houston lead to 74-72 late in the third quarter.
Guard Iman Shumpert gave the Knicks a 61-59 edge with a jumper with 7:54 left in the third quarter. Then the Rockets went on a 13-4 run to move ahead 72-65 with 2:59 left. Harden led the spurt with seven points on a 3-pointer and two driving layups.
Anthony dropped in 26 first-half points, his high in one half this season. He was 11 of 15 from the floor.
Anthony nailed two 3-pointers and Bargnani drained one trey and a mid-range jumper, all late in the second quarter, to trim Houston's lead to 53-50 at the half.
The Rockets built a 38-29 lead with 7:52 left in the second quarter with Howard and Harden on the bench.
The Knicks committed seven fouls in the first quarter and Houston took advantage, making 11 of its 12 free throws to help it to a 28-23 lead. Lin was 6-for-6 from the stripe.
NOTES: Rockets F Greg Smith limped off the court with 1:46 left in the first quarter after landing awkwardly fighting for a rebound with Knicks F Carmelo Anthony. Smith did not return. ... Knicks C Andrea Bargnani scored 24 points, the third time this season he scored more than 20. ... Rockets F Chandler Parsons scored 22 points. ... Houston H James Harden is third in the league in scoring, averaging 26.1 points per game. ... Rockets C Dwight Howard leads the league in rebounds (14.9 per game). ... Houston F Terrence Jones made his second start of the season, and he finished with six points and eight rebounds. ... In their four consecutive home losses, the Knicks were outscored by an average of 12 points while allowing 110 points per game.