Coming home carrying a three-game losing streak, the Nets went into Sunday’s matchup against the Pistons needing a win in the worst way.

But while the Pistons — who came in with a three-game losing streak of their own and eight losses in their previous 10 — should have been the perfect team to get the Nets back on track, nothing comes easy in Brooklyn.

Easy it wasn’t, but the Nets eventually emerged with a 110-105 victory in front of a sellout crowd of 17,732 at Barclays Center.

After Detroit opened the fourth with a jumper from Jonas Jerebko, the Nets looked as if they had put the game away with a 13-3 run largely powered by third-string point guard Darius Morris, who came in to give Jarrett Jack a breather after a short and uninspiring stint in the first half.

But Morris hit Mason Plumlee for an alley-oop and a layup, drained a 3-pointer and then picked up a steal, drove the length of the floor and finished with a nifty reverse layup to give the Nets a 96-83 lead with 6:43 left, sending the crowd to its feet and seemingly putting the game out of reach.

The Pistons had one more run in them, however, pulling to within 104-102 with 41.2 seconds left on an Andre Drummond layup. Then, after Plumlee turned the ball over with a bad pass with 24.9 seconds left, the Pistons came down with a chance to tie or take the lead.

But after the Pistons inbounded the ball with 18.9 seconds left, Jodie Meeks’ 3-pointer from the wing was way off the mark, missing everything and going out of bounds. Joe Johnson then knocked down a pair of free throws to make it 106-102 with 12.5 seconds left, which once again seemed to put the game away — only for Pistons guard Kentavious Caldwell-Pope to knock down an open 3-pointer with 8.9 seconds remaining to make it 106-105.

Johnson was then fouled and again made a pair of free throws to make it 108-105 with 8.7 seconds to play, and Caldwell-Pope’s 3-point attempt to tie the game was short. But once again, when the Nets had a chance to close out the game Kevin Garnett missed a pair of free throws to give Detroit one last shot.

The Nets, though, immediately fouled off of Garnett’s second miss, and when Josh Smith missed both shots for Detroit, Garnett got the rebound, was fouled, went to the line and made both to ensure the victory.