Mayo scored seven straight points in a game-ending 11-6 run that helped the Trojans (3-1) advance to Friday's game against Miami of Ohio, which beat South Alabama 64-59.
San Diego (2-3) will play South Alabama.
But Mayo took over, hitting a runner, banking in a shot, making a free throw and dunking to extend the Trojans' lead to 56-47.
Gibson grabbed 12 rebounds, but USC was outrebounded 35-32, including 13-7 on the offensive glass. Gibson had 12 points in the first half when Mayo had six.
The Toreros turned the ball over 22 times and USC had 20 miscues.
Mayo scored five of the Trojans' first seven points of the second half on a 3-pointer and a fastbreak dunk off a teammate's block to extend their lead to 34-23.
But free throws were a problem for USC, with no one making two in a row until Mayo did with nearly nine minutes remaining. The Trojans went 13-of-22 from the line.
Daniel Hackett and Dwight Lewis hit back-to-back 3-pointers to keep USC ahead 47-37 with 5:42 remaining. But De'Jon Jackson scored five in a row to cut the Toreros' deficit to 47-42 before Mayo dominated.
Mayo's presence helped attract 29 NBA scouts who were credentialed for the new eight-team tournament.
The Trojans led by nine in the first half before San Diego ran off nine consecutive points to trail 27-23 at the break despite shooting 33 percent from the floor. Both teams committed 12 turnovers in the sloppy half, with San Diego scoring 14 points off USC's miscues. The Toreros didn't have an assist in the half.