Cooper Flagg of Newport, Maine, is seen at the training camp for the U17 World Cup national basketball team. Credit: Courtesy of USA Basketball

Team USA found itself in uncharted waters in Sunday’s FIBA World Cup Under-17 championship game against host Spain.

The Americans trailed in the second half for the first time and by as many as seven points in the third period before Nokomis High School of Newport star Cooper Flagg played a pivotal role in rallying Team USA to a 79-67 victory in Malaga, Spain.

The 15-year-old Flagg had seven of his game-high 17 rebounds in the third quarter as the Americans used a 21-3 run to close out the period and transform a 48-41 deficit into a 62-51 lead that they never relinquished.

The 6-foot-8 forward, one of just three 15-year-olds on the team, triggered a 7-0 run that tied it 48-48 with a free throw.

He also had two rebounds and a steal in the spurt.

Izan Almansa Perez’s free throw snapped the run to give Spain a 49-48 lead with 2:53 to go in the period but Flagg made a steal and, 14 seconds later, Jeremy Fears Jr. converted a layup to give Team USA the lead for good.

Flagg came up with another steal, his third of the quarter, and fed Fears Jr. for a dunk to expand the lead to 52-49 with 2:25 remaining.

Fears’ steal and layup and two Flagg free throws made it 56-49 before Hugo Gonzalez Perez sank a layup to slice the lead to five.

Two Flagg defensive rebounds and two Fears Jr. assists set up 3-pointers by Johnuel Omari Fland in the final 33 seconds to make it 62-51.

Flagg didn’t start the fourth quarter but came off the bench with 7:01 remaining and nailed his only 3-pointer of the game with 6:19 left to make it 69-59 and give the Americans some valuable breathing room.

He added four rebounds, two steals and three blocked shots over the final 7:01 to go with his 3-pointer. He also dished out two assists while playing 26:39 off the bench.

Flagg finished with 10 points and he also had a game-high eight steals to go with his 17 rebounds. His rebound and steal totals were tournament-highs for him and his four blocked shots matched his previous high that he posted against Mali.

He shot 3-for-11 from the floor.

Team USA went 7-0 in the tournament and has now won all 44 games it has played in the FIBA Under-17 World Cup Basketball event since its inception 10 years ago. This is its sixth title.

France beat Lithuania 66-58 in the third-place game.

Flagg finished the tournament averaging 9.3 points, 10 rebounds, 2.4 blocked shots and 2.4 steals in their seven contests.

Flagg teamed with twin brother Ace to lead Nokomis to its first state Class A boys basketball championship this past season and became the first freshman to ever win Maine’s Gatorade Player of the Year Award.