Wizards guard Bradley Beal rises up for a shot over Knicks forward Carmelo Anthony. (Maddie Meyer/Getty Images)

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.

Three of the Wizards’ previous four games came down to the final possession, and each time Washington failed to execute. But after Udrih put the Knicks ahead by one with a free throw, Coach Randy Wittman decided to put the ball in the hands of the far-from-rusty Beal and let him determine the outcome.

Wall handed the ball to Beal, and the Wizards cleared out and let him go one-on-one. Noticing confusion from the Knicks, that no double-team was coming and that the rim was unprotected, Beal lowered his head and attacked the basket. After Beal made the go-ahead layup, the Knicks failed to call a timeout — despite possessing three — and Trevor Ariza and Wall forced Anthony (32 points) into an off-balance runner from 25 feet.

“Desperate measures call for big-time shots. And that happened — especially from Brad,” said Martell Webster, who scored 30 points and made six three-pointers after being moved back into a reserve role with the return of Beal. “The last eight points. Pretty amazing. Go back and watch that and you can see the kind of player that kid is trying to become.”

Webster failed to make a three-pointer in either of his first two games since returning from a sprained left ankle, but he rediscovered his shooting stroke at the right time. The Wizards also found their rhythm from long distance, connecting on 11 of 18 three-pointers after making a combined seven three-pointers in their previous two games.

Wall said at the morning shoot-around that the Wizards had to put a stop to their recent slide. He came out and backed up his talk in the first half, scoring the Wizards’ final nine points of the second period and collecting 19 points, five assists and four rebounds as the Wizards took an 11-point lead at the break. Wall only scored one point in the second half and made several blunders in the final minutes, with an air ball, a blocked layup and a turnover when he slipped. He also fired a pass off Udrih and then watched as it bounced off him and slid out of bounds.

“We wanted to get a win,” Wall said. “We felt like we gave away three of the last four games we played. It was great to have Brad back. Hopefully Nene is back soon, but that is no excuse for losing those tough games.”

The Wizards arrived in New York in a funk after getting embarrassed at home by the Los Angeles Clippers two days before. Nene missed his fourth straight came but warmed up on the court in New York, leading Wittman to believe he could return Wednesday when the Wizards take on the Brooklyn Nets.

The Wizards led 59-44 when Ariza came swooping through the lane for a fallaway jumper, but they unraveled during an Anthony-fueled barrage. Anthony scored 13 in the third period and gave the Knicks a 77-71 lead.

Webster scored the final four points of the period, including a difficult, off-balance jumper as time expired to help the Wizards enter the fourth quarter down two. With Wall watching from the bench, backup Garrett Temple ran the team as it rallied to go ahead 92-85, capped by a Beal pull-up jumper. Wittman put Wall back in, but the Wizards couldn’t hold on. They left Anthony wide open in the right corner for a three-pointer that brought the Knicks within two, then let J.R. Smith make two more three-pointers to put them ahead 98-94. But Beal made sure they could finally leave New York with the upper hand after a seven-year wait.

“That was a long time ago,” Beal said.

“It was a hell of a game,” Wittman said. “Brad made a hell of a decision there. Everything didn’t go our way. We made some mistakes. But that’s a step in the right direction.”