SAN ANTONIO — The Knicks were not in awe of the Spurs or their unbeaten streak inside their building. Ending that 30-game winning streak, not how much of an upset it would be, was all that was on their minds.

They had a shot, but in the end, the Knicks were the ones upset Friday night. They nearly erased a 12-point fourth-quarter deficit and had a good look to end the game, but Jose Calderon’s corner three-pointer was a little long, and the Spurs escaped with a 100-99 win.

“It’s a tough one,” Carmelo Anthony said. “I thought this was a game we could go out there and get. This wasn’t a game where we came in and thought, ‘We’re playing against the Spurs. We’re going to lose this one. It’s going to be cool if we just play hard.’ I felt like we could come in here and get a win.”

The Spurs (32-6) improved to 22-0 at home this season and extended their overall streak at the AT&T Center to 31 games.

After taking the first two games of this trip — at Atlanta and Miami — to extend their winning streak to three games, the Knicks (18-20) showed a lot of heart in battling the Spurs to the very end. Down 92-80 with 4 1⁄2 minutes remaining, they had a chance to win on the last play.

It was tougher for Anthony that he didn’t take the final shot. After the final buzzer sounded, he leaned over, wondering if he should have shot it instead of passing to Calderon.

advertisement | advertise on newsday

Derek Fisher came over and told Anthony he did the right thing, based on the way the Spurs defended him. After seeing the replay, Anthony concluded he “made the right play.”

After Tony Parker missed a jumper with 20 seconds left, Fisher could have called timeout but didn’t because he didn’t want the Spurs to set up their defense.

Langston Galloway got the ball to Anthony and he was smothered. Defensive player of the year Kawhi Leonard was on him and Parker and Manu Ginobili went over to help, so Anthony found Calderon in the corner.

Calderon said he shot the ball “a little higher” because he saw Ginobili racing toward him and didn’t want him to block it. That might have made it a little long.

“It was a good look,” Calderon said. “Too many good things happened. I know everybody is going to want me out of New York because I missed that shot.”

Knicks videos

Fisher said he thought about calling a timeout to set up a final play. On the previous possession, he drew up a good one that led to an alley-oop dunk by Kristaps Porzingis that made it 100-99, but he decided it against it this time.

“It’s not easy to get the basketball inbounds and to the players you want the ball to go to,” Fisher said. “I think you can get just as good a shot sometimes just playing it out. Jose was a 41 percent three-point shooter, open in the corner. I don’t know if we would have found a better shot than that if we tried to draw something up.”

Porzingis had 28 points and 11 rebounds. Anthony added 20 points and 12 rebounds but shot 5-for-15 with Leonard and the Spurs suffocating him all night.

Leonard had 19 points and 12 rebounds. Parker (eight assists), Ginobili and LaMarcus Aldridge had 16 points each. Parker had missed the previous two games with hip soreness.

The Knicks scored nine unanswered points to draw within 92-89 on Anthony’s jump shot with 2:49 to go. After Ginobili’s layup, Arron Afflalo buried a three-pointer to make it 94-92 with 2:03 left. Aldridge hit an open jumper to push it to four, but Anthony made it 96-94 with 1:27 to go.

advertisement | advertise on newsday

Parker scored inside, but Afflalo delivered a long three-pointer to make it 98-97 before the Knicks just came up a little short in the end.

“We got a good shot,” Fisher said. “That’s the goal at the end of the game, regardless of who gets the shot. I thought Carmelo made the right basketball play in that situation. We could draw something up. I don’t know if we could get a better look for one of our better shooters than that.”

advertisement | advertise on newsday