Despite playing far from their best for much of the night, the Nets found themselves precisely where they wanted to be against the Raptors in the fourth quarter of Game 4.

Playing on their home court and having a vast edge in experience, the Nets had a one point lead with five minutes remaining, with a chance to take a decisive 3-1 series lead firmly within their grasp.

But instead of seizing the opportunity against a younger, inexperienced team, the Nets folded, failing to make a field goal in the final 6:12 and allowing the Raptors to score the final nine points of the game as Toronto emerged with an 87-79 win in front of a sellout crowd of 17,732 inside Barclays Center Sunday night. The series now shifts back to Toronto Wednesday knotted up at two and completely up for grabs.

After the Nets had erased a 17-point first-half deficit and entered the fourth quarter tied at 67, it appeared they had the Raptors — who looked rattled during most of the third quarter — on the ropes. But it was the Nets who spent the fourth quarter looking rattled, coming apart at the seams offensively.

The Nets were a dismal 3-for-17 from the field — including 0-for-6 from 3-point range — in the fourth, while also committing six turnovers. Most of that damage came in the final six minutes of the quarter, with the Nets failing to hit a field goal after Paul Pierce’s layup with 6:12 remaining that gave the Nets a 77-73 lead.

From that point on, the Nets were outscored 14-2, missing their last six shots and committing four turnovers, including three offensive fouls — charges on both Pierce and Joe Johnson, and a moving screen on Kevin Garnett.

“I thought we just got out of character,” coach Jason Kidd said of his team’s collapse. “We were trying to do it individually, instead of making a play for our teammate.”

That’s the kind of thing you would expect to see from the Raptors. But instead it was the team with all of the experience self-destructing late, and with their most veteran players — Williams, Johnson, Pierce and Garnett — combining for all six fourth-quarter turnovers, with Pierce going 1-for-3 from the field and Williams missing all four of his shots.

“It shouldn’t happen,” said Pierce, who led the Nets with 22 points. “But I thought we rushed a lot … you get in a playoff situation, one guy or two to three guys want to do it on their own, instead of just running our offense, executing. I think we got caught up into that.

“When we run our plays and we’ve got movement, we seem to score most of the time, but I just think we got out of our offense and that can’t happen in the playoffs. It’s got to come down to execution.”

All the Nets managed to execute in the fourth quarter was a message to all employees at Barclays Center to be ready for work Friday, when this series will return to Brooklyn no matter what happens in Toronto on Wednesday.

But after the Nets — for the second time in this series — blew a chance to take a two-game lead and put a stranglehold on the proceedings, Pierce said the only thing they can focus on is regaining the series lead with a win in Game 5 after giving away home-court advantage with their poor showing down the stretch.

“We can’t dwell on that,” Pierce said. “You can’t get caught up in the emotions, see what you could have done. … We’ve just got to move on.

“I’ve been in too many playoffs. There’s so many emotional highs and lows going throughout the playoffs, and you’ve got to understand that. We’ve just got to move forward and say we’ve got to get the next one, we’ve got to win on their floor again, and that’s it.”