Botswana forced Egypt to a 1-1 draw at the end of the African Cup of Nations qualifiers on Tuesday, ending Mauritania's hopes.
Botswana has qualified for the finals hosted by Morocco next year, and will appear in the tournament for the second time in its history.
Egypt, which had previously secured qualification to the finals, raised its score to 14 points at the top of Group C, compared to 8 points for Botswana, which snatched second place.
Mauritania has 7 points in third place after its 1-0 victory over Cape Verde, which is in last place with four points.
Botswana snatched a surprise lead through Umtala Kibatho from close range in the eighth minute in goalkeeper Mustafa Schubert's first ever match with the Egyptian national team.
Mahmoud Hassan “Trezeguet” equalized with a powerful low shot from outside the penalty area at the quarter-hour mark.