Belgium, seen by many as genuine contenders in Brazil, were losing to Sofiane Feghouli’s first-half penalty until coach Marc Wilmots made all three substitutions by the 65th minute.
First Fellaini levelled with a towering header 20 minutes from time then Mertens, sent on at the interval, rifled home Eden Hazard’s 80th-minute pass.
Kevin De Bruyne played a key role in both goals having struggled as much as anyone in the first period.
Belgium were ponderous throughout the first half, despite enjoying the lion’s share of possession. Hazard and De Bruyne saw plenty of the ball but struggled to break down an organised Algeria leaving Romelu Lukaku isolated and out of the game.
With Rafik Halliche and Madjid Bougherra confidently marshalling the penalty area, Belgium began to rely on longer-range attempts, with Axel Witsel finally working Rais M’Bolhi with a drive from 25 yards.
Algeria needed to make the most of their own breaks and duly won a penalty with their first serious foray. Nabil Bentaleb started things by releasing Faouzi Ghoulam on the left and his whipped cross from the left was heading for Feghouli.
The striker might not have reached it but Jan Vertonghen rendered that academic when he made a mess of his tracking run and felled his man. Feghouli eyed Thibault Courtois all the way as he rolled his shot home.
Belgium attempted to respond but were drawing blanks. De Bruyne and Vertonghen wasted a pair of promising free kicks and Witsel saw a second decent strike saved after taking the ball down on his chest.
Hazard’s line-break gave Nacer Chadli sight of goal before the interval but he shot tamely at M’Bolhi and was replaced by Mertens at half-time.
The sides exchanged half-chances from corners, Witsel heading over and Carl Medjani flicking past the far post.
By 65 minutes Wilmots had made two more substitutions, Divock Origi and Fellaini on for Lukaku and Mousa Dembele.
Origi had a great early chance, going one-on-one with M’Bolhi only to see his low effort well stopped by the advancing keeper.
It was Fellaini who made the difference, rising to head De Bruyne’s curling cross in off the underside of the bar.
Wilmots’ changes continued to reap benefits when Mertens put his side ahead 10 minutes later. De Bruyne was involved again, this time winning back possession by tackling Feghouli.
That set in motion a swift counter and Hazard read the situation perfectly, drawing the defence before finding Mertens, who rifled home.
Taken from ESPN