A dream start for Mali gave them a first win in this year's African Nations Cup, but Angola's goalless draw with Algeria meant both they and Malawi missed out on a place in the quarter-finals.
Frederic Kanoute scored after just a minute thanks to a goalkeeping blunder from Swadick Sanudi and Seydou Keita added a second with a thumping free-kick two minutes later.
Russel Mwafulirwa pulled one back for Malawi after 58 minutes, but he will go to bed tonight ruing a missed header after 71 minutes which could have put his side through.
Instead, Mamadou Bagayoko added another for Mali with four minutes to play, but the result was of no use to either side.
Mali, who needed an Algeria defeat to progress, were 2-0 up in Cabinda within three minutes through two contrasting goals.
The first was lucky, as Sanudi's clearance went straight to Kanoute, who had a simple task to volley into an empty net.
The second was pure class though - a bullet 30-yard free-kick from Keita which arrowed into the top-left corner.
Keita had the chance to add to his tally in the 20th minute but his low shot was dealt with by Sanudi.
After 26 minutes Peter Wadabwa headed a rare Malawi chance high and wide when unmarked at the back post.
The better chances continued to fall to Mali though.
Ten minutes from the break Bagayoko did well down the left channel, producing a neat stepover before firing at goal but the save was comfortable enough for Sanudi.
And in stoppage time, El Hadj Traore lashed a wild shot at goal on the counter-attack when Bagayoko was free in the centre.
Malawi pulled one back after 58 minutes - and it was the ugliest of goals.
Dave Banda's cross reached substitute Atusaye Nyondo who turned the ball back across goal.
A combination of Mali defenders and keeper Mahamadou Sidibe could only get the ball to Chiukepo Msowoya, whose shot was blocked, and Russel finally guided the ball home.
Three minutes later, Keita's powerful strike was turned over by Sanudi - and Mali should have had a penalty when Essau Kanyenda clattered into the Barcelona man, but referee Rajin Seechurn inexplicably saw no offence.
Malawi should have been level after 71 minutes but Russel somehow contrived to miss an open goal from two yards.
Joseph Kamwendo's cross found the striker unmarked at the back post and, with Sidibe stranded, he headed the ball into the ground and over the bar.
Bagayoko compounded that miss with a simple headed goal at the other end, but events in Luanda meant both sides bowed out with Algeria progressing from Group A courtesy of their earlier win over Mali.