Joe Johnson scored 16 points for Brooklyn, including two free throws with 8.8 seconds left that made it a three-point game.
Detroit led by 13 in the second quarter, but the Pistons were only ahead 46-40 at halftime, and they were held to 17 points in the fourth quarter. Greg Monroe led Detroit with 23 points.
The Nets had lost 10 in a row to the Pistons on the road. Brooklyn is 18-1 when facing a team under .500.
Neither team could take control in the fourth quarter, but the Nets went 12 for 14 at the free-throw line in the period. Lopez put Brooklyn ahead 91-88 when he backed Monroe down and made a bank shot with 17.8 seconds remaining.
Monroe's layup with 10.4 seconds left cut the lead to one, and it looked as if Detroit coach Lawrence Frank wanted his team to try for a quick trap off the inbound pass. But the Pistons were called for a foul, sending Johnson to the line.
Jose Calderon had eight points and nine assists in his first home game since being traded to Detroit last week.
Reggie Evans had 10 points and 14 rebounds for Brooklyn, which took advantage of a weakened Detroit interior. Pistons rookie Andre Drummond played less than five minutes because of a sore back.
Deron Williams finished with 12 points and nine assists for the Nets, surpassing the 5,000-assist mark for his career.