Senegal escaped with a slender victory against Uganda in the last 16 and they were again made to work hard to keep their quest for a first AFCON title alive by Benin.
Following a quiet opening hour in Cairo that saw Mane largely shackled, Aliou Cisse's side stepped things up and found a winner 21 minutes from time through Everton midfielder Gueye.
Gueye exchanged passes with Mane and converted into the far corner to book a semi-final date with either Madagascar or Tunisia and end the dream rum of Benin, who were reduced to 10 men late on when Olivier Verdon was dismissed.
Benin focused on keeping out the opposition in the first half, but Senegal did get in behind a couple of times shortly before half-time.
M'Baye Niang and Gueye had shots blocked and Youssouf Sabaly was unable to square the ball to Mane in front of goal for what would have been a simple finish.
Mane's frustrations continued early in the second half as he had a header rightly ruled out for offside.
But the Liverpool forward started to see more of the ball and he played a big part in the winning goal as he linked up with Gueye, who showed great composure after surging through to fire across Saturnin Allagbe.
Mane was denied a goal by VAR four minutes later - the first use of the technology in the tournament - and he then had an attempt kept off the line by Emmanuel Imorou.
Verdon was shown a red card for bringing down Gueye in the 82nd minute as Benin's first quarter-final appearance ended in defeat.