The Knicks have spent the first two weeks of the season guarding like champions and scoring like a team still in preseason.

Monday showed both sides of it.

The Knicks trailed the Nets, 79-75, after three quarters at Madison Square Garden, then opened the fourth on a 25-5 run, held Brooklyn to 11 points in the period and won 103-90. They outscored the Nets 28-11 in the fourth and improved to 3-4.

That’s the story of this team so far: a defense good enough to keep the Knicks in every game, and a half-court offense that keeps giving games away. Monday’s fourth quarter showed what the fix looks like: stops turning into early offense. The players who made it happen said one quarter didn’t solve anything.

“No, the issues are still there. I think defensively, we were solid. I think this year, for the most part defense has been pretty good. Obviously there’s been some lapses … So the defense is there minus some spurts. But our offense has to get in a better flow, and that’s kind of what’s holding us back right now,” Josh Hart said at his locker after the game.

“So [our fourth quarter] doesn’t erase the problem or erase the issue, so you gotta figure that out and get better.”

The numbers back him up on both ends.

Through seven games, the Knicks ranked sixth in the NBA in defensive rating and 22nd in offensive rating, according to Basketball-Reference. They were third in points allowed per game and 27th in points scored.

The four losses were all within single digits: 106-100 to Philadelphia, 107-103 in Boston, 111-102 to Orlando and 98-93 in Philadelphia.

Landry Shamet said nobody in the locker room is satisfied.

“I just think we’ve got to win, and I think it’s still early in the season, and I don’t think anybody in this locker room is satisfied with where we’re at,” Shamet said. “Happy to be in the win column tonight, but, you know, to point to 10 things offensively and defensively that we need to improve on.

“So the good news is there’s no panic there. Some nights right now, it might be the offense ahead of the defense and vice versa. We’ve had a hard time making shots so far early in the season. Tonight a few went in, but then we had some slippage defensively. So, a little give and take, but luckily that’s not the point. The point is for us to continue to get better and we’ll continue to do that.”

The Knicks aren’t smothering everyone. Only three of their seven opponents have been held under 100 points: Detroit (97), Philadelphia (98) and Brooklyn (90). Opponents are averaging 105.1 points, and the Knicks are averaging 106.4.

But the defense has been steady enough that the offense decides the night. The Knicks are 2-1 when they hold opponents under 100 and 3-3 when they score 100 or more. They’ve scored fewer than 100 once, the 93 in Philadelphia on Oct. 30.

Last season’s title team didn’t have this problem. Those Knicks ranked third in offensive rating and seventh in defensive rating, according to Basketball-Reference.

OG Anunoby was asked why the Knicks’ defense is ahead of the offense to start the season as reigning champs.

“We have great coaches. [Brendan O’Connor] and [Darren Erman], they do a great job indicating to us what we need to be doing on the court, and then guys are executing defensively and we’re getting stops. That’s always our goal,” Anunoby said after the game. “We don’t think about it. Even when you said that, I didn’t think about it. There’s always room for improvement though, so always striving for better.”

The fourth quarter Monday was better. Hart was the catalyst. He finished with eight points, six rebounds, seven assists and three steals, and the Knicks were plus-22 with him on the floor before he fouled out in 26:54.

“We finally played fast,” Hart said. “We’ve been playing very slow, very stagnant. We finally got out, we ran.”

The half-court offense was still a grind.

The Knicks shot 31-of-75 from the field and 17-of-44 from 3-point range. Jalen Brunson went 6-of-16 for 19 points, and Karl-Anthony Towns, who had 11 points and 16 rebounds, didn’t score until the second half.

The title team needed time to find itself, too. Tyler Kolek said last year’s Knicks didn’t hit their best stride until the playoffs.

“It’s early in the season. I think everything’s a work in progress,” Kolek said. “Last year, I feel like we probably hit our best stride in the playoffs. So we were a work in progress the whole year. That’s the nature of the NBA season. You gotta keep getting better each and every day, each and every game, and be ready to go.”

The defense is clearly ready to go. The offense is lagging behind. A couple of 3s fall here, a couple of passes reach their targets there, and the Knicks may finally begin looking like their old selves once again.

Shamet said the Knicks know better than to trust one quarter.

“We have to be real with ourselves. And Mike’s great with that, assesses things in film, calls it as it is. Our group’s great with that,” he said. “We all understand that by no means — we’re not taking this as any potential fool’s gold.

“The whole goal right now is to continue to get better, and we want to do that. So that’s the thought process.”