LAS VEGAS — The Orlando Magic led by 18 points with less than five minutes left in regulation of their NBA summer league contest against the Sacramento Kings on Saturday, well on their way to a victory.

They wound up getting that win after some very wild events down the stretch.

Emanuel Terry’s layup off a pass from No. 1 pick Paolo Banchero gave the Magic a 94-92 victory in sudden-death overtime, capping a frantic finish to a game that had a little bit of everything in the final moments.

“That’s a game I’ll probably never, ever forget,” Magic summer coach Jesse Mermuys said.

With good reason. Sacramento closed regulation on a 23-5 run, getting the last six of those points in the final 5.1 seconds on a pair of 3-pointers to force overtime.

The fun was just getting started.

Keon Ellis banked in a 3-pointer with 22 seconds left in the first two-minute overtime, putting Sacramento up 92-89. But the Kings fouled Devin Cannady with 6.2 seconds left, and he swished all three free throws to tie it.

Ellis missed a short jumper with a second left in OT, and Cannady nearly won the game there with a 60-foot heave that bounced off the rim. That sent the teams to a second overtime, sudden death, with the first to score wins.

Banchero was called for a foul on the first Sacramento possession and the Kings would have gone to the line to shoot free throws — but after a lengthy review, the call was overturned. Orlando got the ball, Banchero found Terry down low and the Magic got their winner.

“This was one of the most fun games I’ve ever been a part of,” Cannady said. “I’ve played in the NCAA tournament, obviously I’ve played in NBA games, but this was basketball at its purest.”

Banchero scored 23 points and had six rebounds, six assists and four steals for the Magic. Admiral Schofield scored 14 points for Orlando.

Neemias Queta topped Sacramento with 23 points. Keegan Murray, the No. 4 pick, scored 20 points and grabbed nine rebounds. Queta hit the first 3-pointer in the final moments of regulation to give Sacramento a chance, and Murray made the tying one with two-tenths of a second remaining.

The Associated Press contributed to this story.