Not once but twice.

Josh Smith was called for two questionable fouls in the final 22 seconds to turn a Hawks lead into a 106-104 loss to the Knicks Sunday afternoon at Madison Square Garden.

The Hawks held a 104-103 lead after Smith found Al Horford for a dunk with 1:35 remaining.

After a Knicks miss, Smith got the rebound and dribbled up court but was called for an over-and-back infraction. That didn’t hurt the Hawks as they came up with a loose ball on the ensuing play.

Then came the foul calls.

Smith was whistled for fouling Raymond Felton while setting a screen for Jeff Teague with 37.4 seconds remaining.

Carmelo Anthony, with Smith guarding him, drove to the basket for a layup. He went under the outstretched hand of Smith, who was called for the and-one foul. He completed three-point play with a free throw with 12.5 seconds left.

“I have not seen the instant replay,” Hawks coach Larry Drew said. “I couldn’t tell you if it was a foul or not, honestly.”

The Hawks had a final chance. Jeff Teague drove into the lane and kicked out to Smith when the Knicks defense collapsed on him. Smith missed the shot and the Knicks escaped with a narrow victory on a night the Hawks shot 60 percent from the field.

“We can agree to disagree on those calls,” Smith said. “They definitely were the difference makers. Nothing you really can do. We still had a chance to win the game after that. We just fell short.”

Drew said the Hawks ran the final play as planned with Teague driving to the basket.

Anthony finished with a game-high 42 points, including nine 3-pointers. The Knicks forward tied the franchise record for 3-pointers in a game.

“Obviously, Carmelo had a great shooting night,” Kyle Korver said. “He made nine 3’s and they needed them all. He makes eight and we win the game. When he gets on a roll one-on-one he’s probably the best player in the NBA. He’s so big and strong.”

Teague led the Hawks with 27 points. Smith (20 points), Horford (16), DeShawn Stevenson (15) and Korver (13) were the other double-digit scorers for the Hawks.

The Hawks became the first team in the NBA this season to lose while shooting 60 percent from the field. The Hawks made 39 of their 65 attempts.

In the end, it was too much Anthony. He was 15 of 28 from the field, including 9 of 12 from long range. Anthony tied the Knicks record for most consecutive 20-point games at 29. He is tied with Richie Guerin (1961-62), one ahead of Patrick Ewing (1989-90).

“He made shots tonight,” Drew said. “We threw a few different matchups at him. A few of our matchups we actually made a few mistakes of getting sucked in when he wasn’t really involved. We got sucked in on the backside and they swung it over to him and he knocked a couple of shots down.”

The Hawks (25-19) had their three-game win streak snapped. They lost a chance to pull in a three-way tied for fourth in the Eastern Conference with the Nets and Pacers. The Knicks (27-15) remain second, just behind the Heat.

The teams entered halftime tied at 52-52. The Knicks led by as many as 11 points with a 16-0 run between the first and second quarters. The run was triggered by a questionable clear-path foul called on Jannero Pargo.

The Hawks went on a 14-4 run to pull even. They also overcame a five-point deficit in the final two minutes after Anthony hit three straight 3-pointers. They got a Devin Harris steal and layup and Stevenson’s third 3-pointer of the first half.

Teague had 18 first-half points, the final two coming on a layup that triggered a Madison Square Garden fan to scream “Someone stop him!” Anthony had 16 first-half points for the Knicks.

Amar’e Stoudemire could have been called for a flagrant foul after he hit Horford from behind while the center was going up for a shot.