Dallas Mavericks guard J.J. Barea (5) hits a 3-point shot over New York Knicks forward Carmelo Anthony (7) during the fourth quarter of an NBA basketball game Wednesday, March 30, 2016, in Dallas. The Mavericks won 91-89. (AP Photo/LM Otero)
Dallas Mavericks guard J.J. Barea (5) hits a 3-point shot over New York Knicks forward Carmelo Anthony (7) during the fourth quarter of an NBA basketball game Wednesday, March 30, 2016, in Dallas. The Mavericks won 91-89. (AP Photo/LM Otero)

Dallas — J.J. Barea scored 26 points and made the go-ahead layup with 49.9 seconds left as the Dallas Mavericks rallied in the fourth quarter to beat the New York Knicks 91-89 on Wednesday night.

The Mavericks tied the Houston Rockets for eighth place in the Western Conference.

Barea’s basket put Dallas ahead 90-89 after the Mavericks trailed by seven points with 8 minutes left.

Carmelo Anthony scored 31 points for New York and Derrick Williams added 15 in his third start of the season with Kristaps Porzingis out with a shoulder injury.

Anthony lost the ball out of bounds with the Knicks trailing by one. Raymond Felton made one free throw with 8.7 seconds left and the Knicks’ Langston Galloway missed a long 3-point attempt on the final possession.

Wesley Matthews had 16 points and Dirk Nowitzki 11, hitting only 5 of 23 from the floor.

Porzingis re-injured his right shoulder during Monday’s game at New Orleans making a block. He is scheduled to have an MRI later this week.

New York lost starting point guard Jose Calderon to a leg injury late in the first half.

Dallas’ Deron Williams missed his fourth straight game with abdominal and groin strains. The Mavericks lost Chandler Parsons for the rest of the regular season to knee surgery two weeks ago.

The Knicks burst to an 8-0 lead while the Mavericks missed their first six field-goal attempts and led for the entire period. Williams scored eight in the opening quarter, hitting all four shots.

Barea led the Mavericks’ charge late in the half with 14 points, 12 in the second quarter, and seven assists. The final assist came when he was unable to get off a shot while guarded by Anthony and passed to Nowitzki, who hit a 3-pointer with 0.3 seconds left to give Dallas a 51-48 lead at intermission. It was Nowitzki’s only 3-point basket of the game in eight attempts.

New York followed 71 percent shooting the first period by shooting 31 percent in the second. The Knicks then held the Mavericks to 17 percent shooting in the third quarter (4 for 23).

Raptors 105, Hawks 97

Toronto — DeMar DeRozan scored 26 points, Jonas Valanciunas added 19 points and nine rebounds, and Toronto earned its franchise-record 50th victory of the season, beating Atlanta.

DeRozan added six assists and five rebounds, while Kyle Lowry finished with 17 points, 11 assists and six rebounds as Toronto (50-24) won for just the second time in five games.

Toronto became the final franchise in the NBA to reach 50 in a season.

Jeff Teague had 18 points for the Hawks (45-31), whose four-game winning streak was snapped.

Tim Hardaway Jr. added 15 points and Paul Millsap had seven points and nine rebounds for Atlanta, which has won 14 of its last 18 games.

Clippers 99, Timberwolves 79

Minneapolis — Chris Paul had 20 points, 16 assists and eight rebounds, and Los Angeles bullied young Minnesota.

J.J. Redick scored 17 points and DeAndre Jordan had 11 points, eight rebounds and three blocks to help the Clippers win their fourth straight game as they gear up for Blake Griffin’s return. The Clippers held Minnesota to 34.5 percent shooting and only turned the ball over seven times.

Bucks 105, Suns 94

Milwaukee — Khris Middleton scored nine of his 26 points in the final 7:31 and Jabari Parker added 21 points in Milwaukee’s victory over Phoenix.

Milwaukee’s bench outscored Phoenix’s reserves 32-9 in snapping a five-game losing streak. Phoenix has lost four straight and five of six.

Nuggets 109, Grizzlies 105

Memphis, Tenn. — Will Barton scored 25 points, Emmanuel Mudiay had 17 and Denver beat reeling Memphis.

Barton split a pair of free-throw attempts with 3.2 seconds left to help Denver hold on after Memphis pulled within three.

Memphis has lost four in a row. Its advantage over Portland for the fifth seed in the Western Conference is down to two games.

Spurs 100, Pelicans 92

San Antonio — Manu Ginobili scored 20 points and San Antonio beat injury-depleted New Orleans for its NBA-record 38th straight home victory to open a season.

San Antonio topped the 37-0 start by the Chicago Bulls during their record 72-victory season in 1995-96. Golden State (67-7) has an existing 36-game home winning streak to open the season, giving the Warriors a chance to end up with the record.

San Antonio’s Kawhi Leonard had 16 points in his return from a three-game absence, showing no discomfort after bruising his right quadriceps on March 23. The 6-foot-7 forward hit three long jumpers to open the game, including his only 3-pointer in five attempts.

Alexis Ajinca had 18 points for New Orleans, which was without nine players due to injury. Jordan Hamilton added 14 points in his first start in his third game with the team.