Mauritania, for the first time, Guinea and the Ivory Coast later raised to 13 the number of qualifiers for the biennial tournament.
Cameroon, Egypt, Madagascar, Mali, Morocco, Nigeria, Senegal, Tunisia and Uganda had booked places before Sunday.
That leaves 11 places up for grabs during matchday 6 next March with former champions Congo Brazzaville, the Democratic Republic of Congo, Ghana and South Africa among the contenders.
Mahrez, the 2016 African Footballer of the Year, netted either side of a Youcef Attal goal to give the Desert Foxes a three-goal advantage within 30 minutes.
Kodjo Fo-Doh Laba pulled one back for Togo in the second half before Baghdad Bounedjah completed the scoring in stoppage-time.
Algeria have 10 points from five matches in Group D, Benin seven and Togo and the Gambia five each.
An Ismael Diakite goal six minutes from time earned Mauritania a come-from-behind 2-1 victory over Botswana in Nouakchott and qualification from Group I.
Guinea and the Ivory Coast drew 1-1 in a top-of-the-table Group H clash in Conakry with an early Mohamed Yattara goal for the home side cancelled by Jean-Michael Seri.
Burkina Faso, Tanzania, DR Congo and Zimbabwe squandered chances on Sunday to secure places in the newly-expanded 24-team tournament, which kicks off on June 15.
Mateus bagged a brace for Angola in a 2-1 Group I win over Burkina Faso in Luanda while Tanzania fell 1-0 in Lesotho, where Nkau Lerotholi nodded the 76th-minute Group L winner.
William Jebor netted in the second half as Liberia upset Group G leaders Zimbabwe 1-0 in Paynesville while Congo and Democratic Republic of Congo drew 1-1 in the same mini-league.
– Police fired teargas –
The Congo derby was temporarily halted by torrential rain and police fired teargas before the kick-off to disperse supporters seeking entry to an already packed Brazzaville stadium.
Zimbabwe have eight points, Liberia seven, DR Congo six and Congo five and all four countries can be among the top-two finishers and qualify.
Former champions Zambia were eliminated after a 1-0 away loss to Mozambique in Group K in Maputo.
Albania-based Reginaldo Faife kept Mozambican hopes alive of reaching Cameroon by scoring the only goal after 63 minutes.
Guinea-Bissau and Namibia have eight points each after a 0-0 draw in Windhoek on Saturday, Mozambique seven and Zambia four.
Zambia were shock winners of the 2012 Cup of Nations in Libreville, edging the Ivory Coast on penalties after a goalless final.
Defeat was a huge blow for Belgium-born Zambia coach Sven Vandenbroeck, who was hired when local Wedson Nyirenda resigned after the opening round to join a South African club.
Vandenbroeck has won one match, drawn one and lost two in the Cup of Nations since his first appointment to a national head coach post.
He assisted compatriot and Cameroon coach Hugo Broos when the central African country surprisingly won the 2017 Cup of Nations in Gabon.
Ghana defeated Ethiopia 2-0 in Group F in Addis Ababa with recalled Jordan Ayew scoring twice during the first half.
Sudan ended a four-match losing run in Group A with a surprise 3-1 victory over Madagascar in Antananarivo.
A stoppage-time goal salvaged a 2-2 Group H draw for the Central African Republic in Rwanda while Niger came from behind to win 2-1 away to Swaziland in Group J.
For more news your way, download The Citizen’s app for iOS and Android.
Download our app and read this and other great stories on the move. Available for Android and iOS.