The struggling Brooklyn Nets were looking to kill time off the clock late in the game and nearly shot themselves in the foot.

Andray Blatche scored 24 points, Joe Johnson added 21 and the Nets snapped a five-game slide after surviving a late meltdown to slip past the Toronto Raptors 102-100 on Tuesday night.

“The guys said enough was enough,” Nets coach Jason Kidd explained. “These guys have a bunch of pride and they understood what they had to do against the division-leading Raptors and got us a big win on the road.”

Paul Pierce netted 16 points and Kevin Garnett contributed 12 for the bottom-feeding Nets, (4-10), who posted their first victory since November 15 over Phoenix.

“They’re still some things we have to work on,” Pierce said. “We didn’t close out the game but at the end of the day when you’re on a losing streak it’s just great to get a win.”

Pierce thought the Nets stopped being aggressive after building a big fourth-quarter cushion. “It seems like we wanted time to run out instead of putting our stamp on the game,” he said. “We have to push the lead and not wait for the clock to run it. We turned the ball over and fortunately we built such a big lead or we would have lost the game.”

The Nets led 101-86 on Blatche’s put-back lay-in with 5 minutes 22 seconds left but they suffered a meltdown with shoddy play and turnovers.

“I think we got out of synch offensively to the point where we didn’t know what we were running,” Johnson said.

The Raptors took advantage and Rudy Gay’s 3-pointer from the left wing capped a 14-0 tear, making it 101-100 with 23.7 ticks left.

Shaun Livingston was fouled with 11.2 seconds left and missed the second of two free-throws at the other end, giving the Raptors a shot to tie or go ahead.

Gay couldn’t find any openings out of a timeout, and spotted Amir Johnson in the left corner. But his potential game-winning 3-pointer missed and Steve Novak couldn’t get the tip-in to fall at the buzzer.

“We played through all kinds of mistakes, withstood them and won the game,” Garnett said. “That’s what’s most important.”

DeMar DeRozan scored a game-high 27 points, Kyle Lowry added 24, while Gay finished with just nine for the Raptors (6-8), who remain atop the weak Atlantic Division despite a losing record.

“Amir was open, that’s a three he could make and we’ll live with that,” DeRozan said. “He hits it we win, but it stinks that we had to fight back. We waited too long when we were down to throw a punch back.”