Zambia reached the African Nations Cup quarter-finals as a dramatic final day in Group D saw Gabon - top before kick-off - miss out on qualification.
Goals from Rainford Kalaba and James Chamanga earned Herve Renard's side a deserved victory in Benguela despite substitute Fabrice Do Marcolino's late consolation.
But it came at a price, with both Kabala and centre-half Kampamba Chintu collecting bookings which rule them out of the last eight clash.
Gabon goalkeeper Didier Ovono, impressive earlier in the group, made an unconvincing early save from Felix Katongo's long-range drive and an even better chance followed as James Chamanga laid off Katongo's low cross to Jacob Mulenga.
The forward had scored in both the draw with Tunisia and the defeat to Cameroon, but blazed into the side-netting on this occasion.
Daniel Cousin's mis-hit had to be hacked clear by Stophira Sunzu after a rare moment of panic for the Chipolopolo - the Copper Bullets - defence, but they were soon back on the attack and should have taken the lead.
A superb passing move between Mulenga, Christopher Katongo and Kalaba set up Felix Katongo, but he mis-kicked the ball dismally wide.
Kalaba failed to make contact after Felix Katongo cleverly rolled a free-kick to his feet, but he made amends after 28 minutes.
Running onto a delightful through-ball from Felix Katongo, he clipped the ball neatly beyond Ovono to score.
Gabon sought a response, and only Chintu's fine interception prevented Cousin's through-ball reaching Roguy Meye.
But it was Zambia who went close to a second as Katongo's free-kick was headed millimetres wide of goal by Sunzu.
Kalaba fired a free-kick over the bar early in the second half but Zambia soon hit the target once more.
Chamanga tapped home their second in the 62nd minute following an excellent turn and low cross from Mulenga.
Ovono saved well as Mulenga was put in behind the offside trap but finished weakly, and Do Marcolino then halved the deficit.
The striker, who had only been on the pitch five minutes, was picked out in space inside the box and, though his clumsy control almost saw the chance escape, he found the net via an enormous deflection off Emmanuel Mbola.
Relentless Gabonese pressure followed in the final seven minutes, but Do Marcolino smashed a free-kick into the wall and Pierre Aubameyang saw another deflected over as Zambia hung on through four agonising minutes of stoppage time.
Cameroon's 2-2 draw with Tunisia in Lubango left the Indomitable Lions, Zambia and Gabon level on points, head-to-head record and goal difference but the Black Panthers missed out on goals scored.