Marcus Morris matched a season high with 29 points as the visiting New York Knicks overcame a triple-double by Luka Doncic and ended a four-game losing streak by holding on for a 106-102 victory over the Dallas Mavericks on Friday.

The Knicks bounced back nicely from consecutive blowout losses to Sacramento and Detroit that dropped their record to a league-worst 1-7 by overcoming Doncic’s fourth triple-double of the season and winning their first meeting against their former center, Kristaps Porzingis.

Doncic set a career high with 38 points while collecting 14 rebounds and 10 assists, but he also committed eight turnovers — one shy of his career high.

Porzingis added 28 points and nine rebounds before fouling out in his first meeting since the trade from New York on Jan. 31. After the game, he shared a handshake with Knicks coach David Fizdale.

Morris helped the Knicks get their second win by hitting 10 of 22 shots, including 4 of 8 from 3-point range. New York held on down the stretch and overcame going 18 of 31 from the foul line.

Knicks forward Julius Randle added 21 points and eight rebounds, including a clutch jumper and two key free throws down the stretch. Bobby Portis contributed 14 points and 12 rebounds while Frank Ntilikina finished with 14 points and also helped defensively on Doncic at times.

Taj Gibson contributed 12 points and eight rebounds while starting at center for New York in place of Mitchell Robinson (concussion).

The Knicks held a 101-92 lead after Randle’s turnaround jumper with 1:49 left, then sweated out the finish. Doncic reached his triple-double by connecting with Tim Hardaway Jr. on a 3-pointer with a minute to go, making it 101-97.

Doncic then pulled Dallas within 103-99 on a floater with 36.5 seconds left. After New York rookie RJ Barrett missed two free throws with 33.3 seconds to go, Randle seized the offensive board and hit two free throws with 30 seconds left for a 105-99 lead.

Hardaway’s corner 3-pointer over Barrett with 27.6 seconds left made it 105-102, and Dallas had another chance at the tie after Gibson missed two free throws with 25.7 seconds to go. Doncic raced over midcourt, but with Ntilikina lurking nearby, he missed a 3-point attempt from well beyond the arc.

Randle subsequently made one foul shot to seal the Knicks’ win.