MILWAUKEE -- The Dallas Mavericks arrived in Milwaukee with a four-game losing streak and had already been officially eliminated from the Western Conference playoff picture.

But they looked nothing like a team that might have given up on the season Sunday afternoon, riding a 31-point effort from Harrison Barnes to a 109-105 victory over the playoff-bound Milwaukee Bucks at the Bradley Center.

"At this point, we're playing with pride and trying to build for next season," said Barnes, who scored 15 in the fourth quarter as the Mavericks held off a late Milwaukee comeback attempt. "We're just trying to compete and give it our all every single night. We have a lot of high-character guys in this locker room. We're just trying to trust in each other and play for each other. That's what we did tonight."

The Mavericks (32-44) were strong in all aspects of their game. They shot 52.1 percent from the floor, made 14 of 36 3-pointers and while Milwaukee shot just over 50 percent, Dallas' defense forced 15 turnovers, which it converted into 19 points.

"We treated it the same (as if we weren't eliminated)," said reserve guard J.J. Barea, who sank three 3s and added 17 points off the bench. "I think tonight we started pretty good. We started making shots early and that was huge for the rest of the game."

Giannis Antetokounmpo scored 31 to lead the Bucks (40-37), who came into the game having won three in a row and were looking to lock down the No. 5 seed in the Eastern Conference playoffs.

Antetokounmpo added 14 rebounds, nine assists, four steals and a pair of blocks in 39 minutes of action as all five Milwaukee starters scored in double figures.

But while the offense was clicking, it took a while for the Bucks to get into a groove defensively. Milwaukee made 12 of 18 shots in the opening quarter but Dallas hit 12 of its own, including five from distance, to lead by as many as eight before taking a 31-28 advantage into the second.

"We didn't play hard enough, we didn't do what we usually do," Antetokounmpo said. "That's the game, and we move on. We know how important these last five games are for us. We're going to play together and try to finish it off strong."

Thon Maker scored Milwaukee's last eight points of the first half and later knocked down a 3 early in the third quarter to put the Bucks up 56-55. Khris Middleton later hit a 3 from the corner to give Milwaukee a 64-61 lead.

Barnes hit four of six shots and scored 10 in the third for Dallas, but 3-pointers from Middleton, Maker, Tony Snell and Gary Payton II sent the Bucks into the fourth with a 78-75 lead. A 10-2 Mavericks' run capped off by back-to-back 3s from Barea made it an 85-80 game with 10:12 to play.

Dallas had to play without Nowitzki down the stretch after he left the game with a sore right Achilles, but pushed its lead to as many as 11 before a Matthew Dellavedova 3 cut the Bucks' deficit to six with 6:38 remaining.

After falling behind by 10, Milwaukee recovered. A shot-clock violation gave Milwaukee the ball and a Middleton jumper made it a 104-100 game. A foul on Greg Monroe sent Barnes to the line for a pair.

Dellavedova drained a 3 to make it 106-103 but a fadeaway from Barnes restored the five-point cushion with 20 seconds remaining.

"I thought the guys fought, we got back into the game and then we took control of the game and then we gave it back to them," Bucks coach Jason Kidd said. "We fought there, we have to be perfect there down the stretch and we weren't.

NOTES: Mavericks F Dirk Nowitzki scored 17 points but left the game with 10 minutes remaining because of soreness in his right Achillies and did not return. ... G Gary Payton II made his NBA debut Sunday, scoring five points in nine minutes after signing a multi-year contract with the Bucks earlier in the day. Payton, 24, made 49 starts for Rio Grande Valley of the D-League this season, averaging 14.1 points, 6.5 rebounds and 3.3 assists. ... Dallas G Seth Curry sat out Sunday after aggravating an injury in his left (non-shooting) shoulder Friday at Memphis. PG Yogi Ferrell started in place of Curry against the Bucks. ... The Mavericks have won eight of their last nine meetings with the Bucks.