John Wall matches teammate Marcin Gortat’s 31 points Thursday as the Wizards move two games above .500 with their first win over the Raptors after three losses this season. (Tom Szczerbowski/Usa Today Sports)

As the night wore on and the legs grew heavier, the Washington Wizards and Toronto Raptors were driven simply by desire. They traded clutch shots and a few elbows, made ferocious rallies, lost players to injuries and disqualifications and were undeterred as the game extended beyond 48 minutes to 53 and then to 58.

The Wizards needed Raptors point guard Kyle Lowry to barely miss a floater off the front rim at the end of the regulation and John Wall to viciously block Lowry’s layup at the end of the first overtime. They had an apparent, double-clutch game-winning shot by Bradley Beal waved off in the second overtime because it came too late.

Already shorthanded, the Wizards lost two more players when Marcin Gortat and Trevor Ariza fouled out in the third extra period. But Washington finally prevailed in the franchise’s first triple-overtime game since 1975 after Wall made two steals and a layup that mattered most, willing his team to a thrilling 134-129 victory.

“It was a tough fight to the end,” Wall said after scoring 31 points with nine assists. “I’m very tired. But I had to do whatever it took to get a win. Just giving the extra effort. We knew it was going to be a battle. We stuck with it. This was a challenge for us to compete for four quarters, and it turned into seven quarters, and we came out with a win.”

Gortat matched Wall with a career-high 31 points and added a game-high 12 rebounds and four blocked shots to help the Wizards (30-28) win their fifth straight for the first time since April 2012 and surpass their win total from last season with 24 games remaining.

The Post Sports Live crew look at whether the Wizards can make a playoff run without Nene in the lineup for the next six weeks. (Post Sports Live/The Washington Post)

The Wizards came to Toronto with one purpose. All of the ancillary accomplishments that came with it were nice, but avoiding a season sweep against a team they could very well meet in the playoffs was at the top of the list. “We’ve got to beat them,” Beal said before the team caught a flight north. “That’s our biggest goal.”

After a 63-minute slugfest that featured 19 ties, 15 lead changes, a combined 208 field goal attempts and five players playing 50 minutes, the Wizards improved to 3-6 in games that extend beyond regulation, overcoming a 34-point effort by Raptors all-star guard DeMar DeRozan and 26 from former Maryland guard Greivis Vasquez.

Vasquez committed two costly turnovers in the final overtime, with Wall pilfering him on both occasions to set up a breakaway dunk by Ariza (16 points, 10 rebounds) and a layup by Martell Webster to give the Wizards a four-point lead. Then, after DeRozan added two free throws, Wall made a beeline to the basket for a layup with 29.9 seconds remaining that forced Raptors Coach Dwane Casey to call a timeout and sent fans back out to sub-zero temperatures outside.

“We definitely owed those guys,” Wall said. “They had our number all year, doing whatever they wanted and getting whatever they wanted against us. Just happy to finally get a win.”

The Raptors had claimed the first three meetings in relatively comfortable fashion, winning by a combined 31 points. Toronto led by at least 20 in their past two games at Verizon Center, and the Wizards were forced to give the Raptors credit for playing harder. Washington didn’t want to have effort be an excuse Thursday, even if they were running short on players.

In a desperate act in the final minutes of the teams’ previous meeting, the Wizards went small and discovered a way to finally match up with one of the Eastern Conference teams that has given them the most trouble. Coach Randy Wittman acknowledged that going with a smaller lineup was “something in our pocket that we have.”

With the Wizards missing Nene for the next six weeks with a sprained left knee ligament and Kevin Seraphin for the second game in a row with a sore right knee, Wittman went extreme with lineups that included 6-foot-9 forward Chris Singleton (13 points, nine rebounds) and Al Harrington both getting time at backup center.

“We went from big to medium to small to midget,” Wittman joked.

The plan worked as the Wizards built a 12-point third quarter lead that was whittled down to one in less than two minutes.

Vasquez was thrust into a larger role with the Raptors losing Terrence Ross to a sprained ankle at halftime. And he gave his team a 106-104 lead with 32.6 seconds remaining in regulation when Wall got called for goaltending his layup attempt. Gortat then rebounded a Beal miss and dropped it into the basket to tie the game at 106 with 5.2 seconds remaining.

Lowry’s runner bounded off the front of the rim to force the extra frame. Beal, who has been adhering to a minute restriction, thought he would have to watch the finish from the bench.

“I took my mouthpiece out, and I was like, ‘Dang, I’m not going back in.’ Coach was like, ‘What are you doing?’ ” said Beal, who played a team-high 51 minutes 7 seconds.

Wall helped extend the game to another overtime by scoring six straight points, including a driving layup that tied it at 114 with 23.3 seconds remaining. Lowry tried to win the game on a quick drive, but Wall slapped his shot away and then angrily stepped over him before the second overtime began.

Beal nearly won the game in the second overtime, but his shot came after time expired, wasting an animated celebration from Gortat, who picked up Beal and hugged him before the shot was reviewed and disallowed.

“I really thought we won that game at that time,” said Gortat, who has had six straight double-doubles. “I was so excited. I lifted Brad up, I started celebrating but then everybody told me it’s not good.”

The final result, however, was good. “Earlier in the season, we would dropped our heads if they told us what they told us,” Ariza said about Beal’s shot. “Just shows that we are growing and we’re getting better. We didn’t give into fatigue. We didn’t give into anything.”

Wittman marveled at how his players were able to hold on: “My feet and back are hurting, and I didn’t play.”