The Mavericks built a 20-point lead, then hung on for dear life in the fourth quarter to beat the Brooklyn Nets 98-90 Friday night at Barclays Center.

It was the first time they have beaten a team over .500 on the road since winning at Houston on Dec. 8.

The Mavericks were up 86-66 with under eight minutes left. Barely three minutes later, the Nets had cut the gap to 90-79 and missed two chances to draw even closer. Finally, Williams converted a drive, but O.J. Mayo made a wide-open 3-pointer from the corner when Nowitzki found him out of the double-team.

Still, the Nets wouldn’t wilt. Williams was fouled for a three-point play and Brook Lopez scored in the paint to make it 93-86 with 1:46 still left. The Mavericks couldn’t score as Dirk Nowitzki missed and C.J. Watson drove from the corner for a layup with 1:05 to go.

Vince Carter, who had a 20-point night against his former team, made one of two free throws to make it 94-88, but the Nets still were in position to at least force overtime with 47 seconds left.

Lopez made two free throws but that was as close as the Nets would get as Shawn Marion played tough defense to keep Williams from getting the ball and the Mavericks made just enough free throws to survive.