Nigeria narrowly beat hosts Senegal 1-0 in the first semi-final of the Under-23 Africa Cup of Nations to earn a place in Saturday's final.
Captain Peter Etebo scored the key goal from the penalty spot.
Algeria beat South Africa 2-0 in the second semi after goals from Oussama Darfalou and Mohamed Benkhemassa.
Senegal and South Africa face a crucial third-place match on Saturday, with the winners also earning a place in Brazil.
Just before half-time in a tense match, Nigeria keeper Emmanuel Daniel was both villain and hero.
First he conceded a penalty for a foul on Cheikhou Dieng but he then saved a poor effort from the spot by Ibrahima Sory Keita.
With both sides struggling to find the target, Nigeria coach Samson Siasia brought on the top scorer from the recent Under-17 World Cup, Victor Osimhen.
The match changed in the 75th minute when Nigeria were awarded a penalty after Senegal's Ousseynou Thioune, who was sent off, handled the ball as he collided with his goalkeeper Pape N'Diaye Souare.
Etebo stepped up to do what Keita was unable to do earlier and net an emphatic effort that Souare had little chance of saving.
Senegal's 10 men pushed for the equaliser that would have taken the game to penalties but even with five minutes of injury time left, they were unable to break down the stubborn Nigerian defence.
In the other game, South Africa conceded an early goal against an Algerian side who threatened regularly with their slick counter-attacking.
Darfalou sped unopposed on to a hopeful long pass from captain Riyad Keniche after nine minutes and lobbed the ball over South Africa goalkeeper Jody February.
South Africa fluffed a rare chance to level when Gift Motupa's control let him down.
Algeria knew a second goal would kill off the game and it arrived five minutes after half-time when Benkhemassa rifled a weak clearance into the corner.
Nigeria and Algeria have clinched two of Africa's three places in the men's football tournament for next year's Olympics in Rio de Janeiro.