When Joe Johnson’s 3-pointer splashed through the net to give the Nets a 93-78 lead with 5:02 remaining in Game 3 Friday night at Barclays Center, it appeared Brooklyn was going to cruise to 2-1 advantage in the best-of-seven series against the Raptors.

“Honestly, we got a bit lackadaisical,” Johnson said afterward.

That’s one way to say it.

Just when it looked as if the Nets would coast home to a victory, they allowed the Raptors to immediately jump back into the game with a 18-4 run over the next four-plus minutes that pulled them all the way to within one inside the final minute of play. Toronto later had a chance to tie the game inside the final 20 seconds before the Nets finally emerged with a 102-98 win in front of a sellout crowd of 17,732.

“The way we were playing over there, I’m sure we gave him a heart attack,” Shaun Livingston said, referring to Nets coach Jason Kidd, with a smile and a shake of his head. “I think he expects more from a veteran team, from veteran players.”

The Nets seemed to expect more from themselves than the way they played in the final few minutes, when they let Toronto back into the game. They nearly suffered a disastrous loss that would have equaled their collapse late in the fourth quarter of last year’s triple overtime loss to the Bulls in Game 4 of their first-round series a year ago.

This time, however, the Nets were able to hang on despite missing four free throws in the final minute alone, including three by Deron Williams, marring what was an otherwise sensational game that saw him finish with 22 points, eight assists and just two turnovers.

“By no means did we close the game out like we wanted to,” said Paul Pierce, who had 18 points, echoing the feelings of a much more annoyed locker room than usual after a playoff victory.

“Teams get better, and if you go to the next round, you can’t afford those mistakes. It’s best we take care of them now.”

After Johnson, who finished with 29 points to lead the Nets, hit his 3-pointer with 5:02 remaining, the Raptors rattled off eight consecutive points, and then scored five more after a Johnson floater to make it 95-91 with 1:07 left.

It looked as if the Nets finally had the game in hand when Williams drove down the lane and drew a foul on Greivis Vasquez, who then picked up a technical for arguing the call and sent the point guard to the line for three free throws.

But Williams — an 80 percent foul shooter — made just two of the three free throws to give the Nets a 97-91 lead, and then, after DeMar DeRozan made a pair of free throws, Williams was intentionally fouled and missed both free throws to give Toronto the ball down four with 40.7 seconds left.

“He’s human,” Kidd said. “It happens. We’ve all been there before.

“We got the win. … He missed a couple, but we still believe when he goes to the free throw line, he’s going to make the next one.”

It was much easier to say that after the final buzzer. Because when Williams missed them, the game was still in doubt — and became even more so when DeRozan converted an and-one layup with 34.3 seconds left to make it 97-96.

Livingston was then fouled on a drive and made the first free throw to make it 98-96 with 20 seconds left. He missed the second, however, and on the ensuing rebound, Patrick Patterson was fouled by Andray Blatche, sending him to the line with a chance to tie the game. But Patterson, continued the trend for both teams in the final minute and missed both free throws, giving the Nets the ball back.

The Nets didn’t let things slip away this time, as Pierce and Johnson each calmly knocked down two free throws apiece inside the final 20 seconds to seal the win.