Trailing by 20 with 8:23 remaining, Brooklyn stormed back to get within four points with 37 seconds remaining.

But the Mavericks dodged a repeat of Wednesday night's loss at Memphis, closing out the Nets for a 98-90 victory on Friday night behind 20 points apiece from Dirk Nowitzki and former Nets guard Vince Carter.

"We played a lot more good minutes than we played in Memphis for sure. It's hard to play a perfect 48 minutes in this league, I'll admit that," Mavericks coach Rick Carlisle said.

"But we took advantage of our runs. We were able to stave them off a few times. We had some guys step up and hit some big shots. Vince hit one shot off a timeout that was big. O.J. (Mayo's) 3 in the right corner was a huge play. We made a few mistakes, obviously. So hey, we'll take it and run."

Brooklyn's season-long, second-half deficiency caught up to them again. The Mavericks held the Nets to just 5-of-17 shooting from the field in the third quarter before they found their shooting touch in the fourth quarter, hitting 10-of-22 shots.

"We came out and we had a couple of turnovers early and we got really flat after that," Nets interim coach P.J. Carlesimo said.

"We didn't execute well but worse we just didn't play with any defensive energy and the score went from like 10 to 20 in a very short time."

It was a big win for the Mavericks, who still maintain hopes of somehow claiming the eighth spot in the Western Conference despite trailing the Houston Rockets by five games. The Mavericks, who had lost their last three games, will face the Rockets on Sunday night in the opener of a home-and-home set at Houston.

"It's been a frustrating and disappointing season obviously overall. We lost a couple of close games that we thought we should've had," Nowitzki said. "We have to go in with a free mindset and kind of forget what happened so far and let it all rip. Houston is a great team. (James) Harden is having a phenomenal year. They're a tough team. They're fast, athletic. So we got our hands full."

Mayo, who added 17 points, is looking forward to the matchup at Houston after pulling off a road win in Brooklyn, just the Mavs' 10th in 30 tries this season.

"That's a (team that's) ahead of us and gives us the opportunity to gain ground and make them back track a little bit," Mayo said.

"I thought we did our job. We did what was expected. A lot of games this year we've been in and had the opportunity to win down the stretch and at the end of the games lose. . A lot of those times we had the lead going into the last five or six minutes and couldn't close it out. I thought we did what we needed to do to win the game."

Deron Williams scored 17 of his 24 points in the first half in his first game against Dallas since deciding to remain with the Nets instead of signing with the Mavericks last summer, but felt his indecisiveness and thinking about when to pass the ball or not played a role in Brooklyn's latest loss at home, its third straight.

"It started with me. I think it is kind of a snowball effect," said Williams, who led the Nets to a 49-48 halftime lead before they had another dismal third quarter. Dallas outscored Brooklyn 29-14, as the Nets shot just 5 of 17 from the field.

"I was throwing the ball everywhere and it is just one of those things where you see a guy making some bad passes and you start thinking about it."

Brook Lopez had 19 points and Joe Johnson added 11 as he returned to the Nets after missing the last three games with a foot injury.

"I think we just put ourselves in a bad position. One through 12, we did not have any energy, no energy on the floor, no energy on the bench and that is tough," Lopez said.

Brooklyn will have to turn it around quick when it visits the Chicago Bulls on Saturday night. The Nets, fifth in the Eastern Conference race, are just a half-game better than the Bulls.

Jae Crowder hit a 3-pointer after a turnover by C.J. Watson, then Mike James hit another behind the arc to give Dallas its biggest lead of the night at 83-63 before Brooklyn started to chip away.

The Nets went on a 17-7 run to cut the lead to 94-90 after Lopez hit a pair of free throws with 37 seconds remaining. Mayo then made one free throw, and Watson missed a layup and failed to tip it in on the second attempt, James was fouled and made one free throw to make it 96-90.

After Williams missed a 3-pointer, Carter got fouled by Mirza Teletovic and put the game away with a pair of free throws to give Dallas a 98-90 lead.

Williams was the Mavericks' top target in free agency, hoping he would be convinced to return to the area where he starred in high school. He said it was a tough decision, deciding to stay with the Nets with a five-year deal worth about $98 million.

He has battled minor injuries throughout the season but has played better of late, though did commit a game-high seven turnovers Friday.

Notes: Brooklyn went 1-2 during Johnson's absence. . New York Giants wide receiver Victor Cruz and TV host Larry King were in attendance. . Watson scored 11 points, all in the fourth quarter.