In a building where the franchise hadn’t won since Bradley Beal was in seventh grade, in a game John Wall deemed a “must-win” and with Brazilian big man Nene again resting his ailing right heel, the Washington Wizards finally put to rest some unsettling trends Monday night with a 102-101 victory at Madison Square Garden.

The cure for what plagued the Wizards came with the surprising return to the lineup of Beal, who rejoined the team after missing the past nine games with a stress injury in his right fibula to score 21 points — 14 coming in the fourth quarter — including a game-winning, driving layup around Knicks guard Beno Udrih with 6.9 seconds remaining.

“That’s number one, of course,” Beal said when asked to rank performance. “It was a blessing to be put in that position, in your first game back in three weeks. That’s tremendous.”

Beal then rebounded an errant, rushed shot by Knicks all-star forward Carmelo Anthony and enthusiastically slammed the ball after the Wizards snapped a 10-game losing streak in New York and a four-game losing streak overall and finally won for the first time in seven tries without Nene. The Wizards (10-13) won in New York for the first time since Dec. 6, 2006, before all but four players on Washington’s roster were even in the NBA.

“I don’t think there’s any other team in the NBA that we want to beat more than the New York Knicks, especially here in Madison Square Garden,” center Marcin Gortat said. “It was a great win.”

Beal made his presence felt in the fourth quarter after the Wizards had watched a seven-point lead turn into a four-point deficit in a matter of three minutes. He made two clutch three-pointers that hushed the crowd — he brought the Wizards within 98-97 with the first, then tied the score at 100 with the second over Knicks center Andrea Bargnani.

“The first one I thought was going to hit the backboard. But the second one I knew for sure. That felt good as soon as it hit my hand,” Beal said afterward.