The Belgians, expected by many to figure as genuine contenders in Brazil, were losing to Sofiane Feghouli's first-half penalty, prompting Marc Wilmots, their coach, to make all three of his substitutions by the 65th minute.
Only five minutes later, he witnessed the effect he had hoped for. First Fellaini equalised with a towering header, 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 side, leaving Romelu Lukaku isolated up front.
With Rafik Halliche and Madjid Bougherra confidently marshalling the penalty area, Belgium began to rely on longer-range attempts and Axel Witsel finally worked Rais M'Bolhi with a drive from 25 yards. Algeria's strategy relied on them making the most of their own breaks and they did so when they won a penalty with their first serious foray into Belgian territory.
Faouzi Ghoulam whipped in a cross from the left which Feghouli might not have reached, 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 De Bruyne and Vertonghen wasted a pair of promising free-kicks and Witsel saw a second decent strike saved after taking the ball on his chest.
Hazard set up Nacer Chadli for a sight of goal before the interval but he shot tamely at M'Bolhi and was replaced by Mertens at half-time.
After the interval, the sides exchanged half-chances from corners, Witsel heading over and Carl Medjani flicking past the far post.
In the 65th-minute, Wilmots made two more substitutions, Divock Origi and Fellaini coming on for Lukaku and Mousa Dembele.
Origi had a great chance almost immediately, going one-on-one with M'Bolhi only to see his low effort well stopped by the advancing keeper.
But 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 once more, 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 fired home.