Percy Tau was the star of the show as he bagged a brace with two beautifully-taken strikes. Bafana needed to avoid defeat but went one better claiming victory, meaning they ultimately finish five points ahead of the Libyans in Group E.
The first decent chance of the game fell to Libya in the 23rd minute. Bafana made a hash of clearing the corner with the ball falling kindly to Ali Elmusrati, but luckily for the visitors, his first-time shot was straight at Darren Keet.
The crowd at Sfax were very vocal, playing the role of a 12th man effectively. Bafana had their first decent attempt in the 38th minute. Lebo Mothiba did well to create the space and find Tau, who laid the ball off for Themba Zwane with the Sundowns midfielder's shot turned behind the bar by Muaid Salem Ali.
It was a pretty scrappy encounter and not easy on the eye but that suited Bafana, who didn't need to score, unlike the Libyans.
The Meditteranean Knights were looking fragile defending set-pieces and Tau was delivering some telling corners in to the box. Shortly before the interval, one such Tau delivery found Mothiba, but the Strasbourg striker was off balance and skied his effort over the bar.
Keet was having an excellent game between the poles, showing good hands to deny Ali Elmusrati on the stroke of half-time.
Bafana started the second half much more brightly and took the lead in the 50th minute through Tau, who smashed a thunderous effort in to the top left-hand corner of the net, with Mothiba having provided the assist after a good build-up.
Soon after, the hosts almost equalized but Keet denied them with a stunning save as he showed tremendous reflexes to get a strong right hand to the ball after a delicious ball in to the box by Hamdou Elhouni was met first time on the volley by Anis Saltou.
In the 65th minute, Libya won a penalty. After Keet came out to catch a high ball, the Bidvest Wits keeper caught Saltou with a trailing leg and the referee had no hesitation in pointing to the spot. Ben Ali converted the spot-kick, to make it a tense last 25 minutes for Bafana.
Tau eased Bafana nerves, however, when he restored the hosts' lead soon afterwards. After the short corner was taken, Sifiso Hlanti laid the ball off to the Brighton and Hove Albion striker, who struck a powerful curling effort, this time on his right foot, in to the left-hand corner.
With 15 minutes to go, Elhouni glided past Thamsanqa Mkhize and hit the ball sweetly towards the top left-hand corner, but Keet pulled off another good save, diving to his left and palming the ball away strongly.
Hlompho Kekana, on as a substitute for Themba Zwane, almost caught Libya goalkeeper Muhammad Nashnoush off his line with a characteristic long-range lob with seven minutes to go.
Tau had a golden opportunity to grab his hat-trick and put the result beyond doubt but fired inches wide after being put through on goal. However, it mattered not as Bafana claimed a historic victory in the end.
Bafana: Bafana: Keet, Hlatshwayo, Mkhwanazi, Hlanti, Furman, Mkhize, Maela, Mokotjo, Zwane (Kekana 78'), Tau (Veldwijk 93'), Mothiba.
Subs: Williams; Coetzee; Modiba; Kekana; Serero; Maboe; Veldwijk.