Searching to finish its longest remaining homestand of the season on a high note after a 1-2 start, the Magic found themselves in a tight back-and-forth contest hosting the Mavericks on Thursday night at Kia Center.

Dallas led by as many as 14 points in the first half before Orlando punched back to take an 11-point lead in the third quarter.

In a contest that featured nine lead changes, No. 1 pick Cooper Flagg put the Mavericks ahead by four points with 37.3 seconds remaining in the game. Jalen Suggs nailed a 3-pointer out of a timeout to bring the Magic within a point.

After Flagg missed a jumper, Suggs brought the ball down the court and sent it ahead to Wendell Carter Jr., who dunked down the game-winner with 1.4 seconds left to help Orlando escape on top 115-114 at home.

Although the Mavericks scored 17 points off 12 Orlando turnovers, the Magic returned the favor on the other end of 15 points off 13 takeaways.

Unable to get off a shot off before the final buzzer, Dallas (21-41) was outscored 56-38 in the paint.

After going 2-2 on their four-game homestand, the Magic (33-28) head back on the road for a quick back-to-back Saturday at Minnesota and Sunday at Milwaukee.

Starting 5

Anthony Black (right quad contusion) and Wendell Carter Jr. (left ankle soreness) returned to the starting lineup alongside regulars Jalen Suggs, Paolo Banchero and Desmond Bane against Dallas.

Black, who had missed the past two games due to injury, got off to a slow start when he opened 1 for 8 from the floor in the first half and picked up his third foul with 40 seconds left in the second quarter. He ended with just eight points in 24 minutes.

Carter, who didn’t play Tuesday against Washington, also found himself in early foul trouble, earning his third foul at the 5:47 mark of the second quarter.

Despite the fouls, Carter made his first three shots from the floor to finish with 15 points and seven rebounds. His last basket was his most important.

Bane only took two shots from the floor in the first 20 minutes of the game and didn’t take his first 3-pointer, which he made, until the 3:10 mark of the second quarter. He scored six points late in the second frame to notch eight in the opening frame.

Banchero failed to take care of the ball with six turnovers but still recorded a double-double by way of 16 points and 12 rebounds.

Suggs hit a pair of 3-pointers in the third quarter, one of which turned into a four-point play, to notch 17 points and seven assists.

Difference from distance

Dallas entered the night averaging the second-fewest made 3-pointers in the league (10.5) while shooting the third-worst 3-point percentage (34%).

The Mavs overcame those poor marks early, shooting 6 for 12 in the opening quarter. Four-time NBA champion Klay Thompson (game-high 24 points) led the charge, hitting three of his first six long-range shots before the break and ending 7 for 12 from distance.

Meanwhile, the Magic missed their first four triples and made just five in the first half.

Dallas ended 14 for 33 (42.4%) from distance while Orlando finished 13 for 39 (33.3%).

Bench boost

Back to the bench with Black starting, Tristan da Silva made his first four shots from the floor to piece together an 11-point first half. His fourth 3-pointer with two minutes left in the game gave Orlando a 1-point lead late.

He and Moe Wagner provided an offensive spark when Wagner searched to score in the paint early with six points in

Veteran guard Jevon Carter hit the team’s first 3-pointer with 2:33 left in the first quarter.

Orlando’s bench outscored Dallas’ 45-41.

Rookie watch

Second-round pick Noah Penda entered the game late in the first quarter and his night was highlighted by a cutting two-handed dunk early in the second frame.

Penda finished with four points and four rebounds across 20 minutes.

It was a homecoming of sorts for Flagg, who finished his high school at Montverde Academy. With dozens of local Flagg fans making their voices heard, the 6-foot-9 wing did a little bit of everything with 18 points, five rebounds and six assists.

Magic first-round pick Jase Richardson didn’t see the floor.

Jason Beede can be reached at jbeede@orlandosentinel.com