After Mexico squandered a two-goal lead with less than 25 minutes remaining, Dos Santos and Herrera capitalized on defensive gaffes and put El Tri within two victories of a gold medal.
Goalkeeper Jesus Corona, who made several dramatic saves through the first 90 minutes, turned away Moussa Konate again in the 105th minute to preserve the victory for Mexico and earn it a Tuesday meeting against Japan.
Jorge Henriquez scored in the 10th minute and Javier Aquino added a second in the 62nd to seemingly put Mexico in control. But Konate and second-half substitute Ibrahima Balde tallied seven minutes apart midway through the second half to force extra time.
Senegal pressed from the outset, capitalizing on an errant pass from Henriquez and had two chances in the first 90 seconds.
But Mexico weathered the early pressure and went ahead when Henriquez shed his marker and ran unmarked through the penalty area to get a glancing header on Dos Santos' free kick from 30 meters and deflected it into the far side netting.
Senegal pushed forward and created several chances, forcing Corona into dramatics to deny Konate four times in an eight-minute span midway through the first half.
The "Teranga Lions" continued their push in the second half, but Mexico doubled its lead in the 62nd against the run of play.
Marco Fabian sprinted down the left, crossed into the area where Oribe Peralta was able to get a touch toward goal that Senegal keeper Ousmane Mane was able to get a hand to. But the ball bounded to Mane's left and an unmarked Javier Aquino pounced on the loose ball into an open net.
But a relentless Senegal still went forward and pulled within a goal seven minutes later when Konate ran onto a left wing cross from Pape Souare inside the six, and headed it past Corono.
Senegal equalized in the 76th, earning a corner that Souare curled to the middle of the area and second-half substitute Ibrahima Balde headed inside the left high corner.
Mexico had the better of play in the extra period and went ahead when Souare made a rare mistake by sending a back pass to Gueye inside his own area with Dos Santos and Peralta nearby. Gueye turned toward his own goal where Dos Santos was able to steal the ball and finish without challenge.
Herrera added the insurance five minutes later when Abdoulaye Ba attempted to head a ball back to Mane, but mis-hit it and Raul Jimenez raced in. Mane came off his line to the top of the area to block Jimenez's attempt, but the rebound dropped in front of Herrera trailing the play and he scored into an open net.