The Magic led by as many as 16 in the game but were clinging to a 112-109 lead when O'Quinn stepped out on Johnson to block his 3-point attempt on the high left side.
After Afflalo made 1-of-2 from the foul line at the other end with 9.2 seconds left, Maurice Harkless fouled Mirza Teletovic on a 3-point try to give him three free throws.
But Teletovic made only two, cutting Brooklyn's deficit to 113-111, and Jameer Nelson knocked down a pair for Orlando to seal the win.
E'Twaun Moore scored 17 points off the bench for Orlando, including 14 in a row in the second quarter to ignite a 21-3 run that gave Orlando its 16-point lead.
Tobias Harris added 16 points and Nelson and O'Quinn scored 14 and 13 in that order as the Magic won their second straight game after knocking off Minnesota on Saturday. They are 4-3 since a nine-game losing streak.
Johnson scored 31 to lead the Nets, who had a three-game losing streak snapped on the heels of Tuesday's 88-87 win over Miami to sweep the four-game season series from the Heat.
The Nets, currently seeded No. 5 in the Eastern Conference, have won six of their last eight. They will face the Magic again on Sunday in Brooklyn, where the Nets have won a team-record 15 straight games. The streak will be put to the test first on Friday against Atlanta.