The Eagles started the day in second place but go through as group winners because previous leaders and hosts South Africa were beaten by Nigeria, who join Mali in the last eight.
Mozambique were beaten convincingly by Nigeria and South Africa in their opening two matches in Group A, but had a half-time lead in Cape Town tonight thanks to Josemar's 38th-minute goal.
Mali were level three minutes after the interval thanks to Ibourahima Sidibe's second goal of the tournament.
It remained level and Mali were set to go through as runners-up until they won a late penalty that Idrissa Traore tucked home.
Next up for Henryk Kasperczak's side will be a quarter-final clash against the runner-up from Group B, again in Cape Town, on Saturday.