Apparently all it took for the Nets to figure things out was to leave the country.

After spending the past five games — and virtually their entire season — struggling to control the paint, win the transition battle and play well in third quarters, the Nets did all three on their way to a 102-100 victory over the Raptors inside Air Canada Centre, but it wasn’t easy.

It looked as if the game was in the bag when the Nets held a 101-86 lead with a little more than three minutes left. But the Raptors went on a 14-1 run, and had the ball with 10.7 seconds remaining after went 1-for-2 at the foul line.

But Rudy Gay drove into the heart of the defense and kicked it out to Amir Johnson, whose corner 3-pointer was short, and Jonas Valanciunas’ tip missed the mark. Coach Jason Kidd put his head in his hands in a sign of relief as he walked onto the court, as the Nets narrowly skirted what would have been a catastrophic loss.

The Nets (4-10), who had lost five straight and eight of their previous nine entering Tuesday night’s contest, needed a win, if for no other reason than to give this team a chance to exhale after injuries and overall ineffective play sidetrack what began as the most anticipated season in franchise history.

After another quality first half, the question was whether the Nets, who have been the NBA’s worst third-quarter team, would be able to shake off their season-long demons after halftime.

This time, however, the Nets jumped out to a quick 10-4 run to open the quarter, with a Kevin Garnett jumper and Joe Johnson 3-pointer followed by five straight points from Paul Pierce that forced Raptors coach Dwane Casey to call a timeout.

As the quarter wore on, however, the Raptors (6-8) slowly clawed their way back into the game, and eventually closed to 77-76 on a Terrence Ross jumper with 1:04 left in the quarter.