That win means the Red Devils finish runners-up behind Italy on goal difference in Group F and they will face Hungary on Sunday in the last 16.
After a goalless first-half, the game opened up and both sides had chances to take the lead in the game, and it was Nainggolan’s strike that sealed the points.
Zlatan Ibrahimovic’s international career has now come to an end as Sweden exit the tournament with only one point, finishing bottom of the group.
Open start to the game
Marc Wilmots’ side came into the final group game knowing only a win would ensure their last 16 fate would be in their own hands.
Both sides came out the blocks quickly and created chances inside the opening minutes, with Sweden going close after five minutes.
Seb Larsson’s free-kick deflected and fell into the path of Marcus Berg, who struck at goal first time, but Thibaut Courtois was on hand to produce a superb reaction save.
And from that save, the Belgians broke immediately, but after Romelu Lukaku drove forward, his drilled cross-shot went agonisingly across the box and wide of the post.
Belgium go close on numerous occasions
The game continued in the same open fashion for quite some time, with Belgium creating chances frequently.
Good team play on the edge of the area saw Lukaku law the ball off to Kevin De Bruyne, who curled at goal and forced Andreas Isaksson into making a low save.
Ibrahimovic had a chance of his own after Berg returned his pass to him just outside the box, but he couldn’t dig his shot out towards goal as the ball went wide.
De Bruyne was causing Sweden all sorts of problems throughout the opening 45 minutes, and on many occasions his drilled crosses needed a player to simply get on the end of it.
But to his despair, nobody was taking the chance to get into the box and into those positions as the sides went in at the break level.
Both sides have goals ruled out
Sweden came out on top, and thought they had the lead in the game just after the hour mark, but Ibrahimovic’s acrobatic finish was ruled out after Berg was penalised for a high foot in the build up.
De Bruyne and Lukaku both had chances thereafter to open the scoring, and the latter should have done better after being played through on goal.
The forward struck at goal, but straight at the keeper, who done well to spread himself, but when Lukaku had the ball in the net moments later, that was ruled out for offside.
Sweden knew they needed to win to get through to the latter stages of the tournament, but Belgium always looked dangerous on the counter and through set-pieces.
Nainggolan strikes late in game
Substitute Dries Mertens drilled at goal before the Swede’s went close again, this time through Berg, whose header from a corner was cleared off the line by De Bruyne.
Time was ticking for both sides, but Nainggolan had other ideas and made Sweden pay for allowing him too much space on the ball.
The midfielder picked up the ball and lashed his shot into the far corner of the goal via a small deflection off a defender, but that sparked jubilant scenes.
Ibrahimovic had one further chance, which he hooked at goal, but wide, and Christian Benteke forced a great save from Isaksson in injury time.