Luciano Spalletti – whose position continues to be the subject of intense scrutiny – said earlier in the week that he wanted his players to treat the game as a "cup final" and they duly responded in the early stages, with only the brilliance of Empoli goalkeeper Bartlomiej Dragowski preventing it from putting the game to bed before half-time.
Keita Balde Diao's introduction at the interval proved a masterstroke as the 24 year-old superbly whipped past Dragowski from outside the penalty area to open the scoring.
Empoli took full advantage of Mauro Icardi's penalty miss soon after, though, to level in the 76th minute through Hamed Junior Traore.
However, Nainggolan slotted home nine minutes from time and a hectic finish saw Inter defender Danilo D'Ambrosio clear against his own crossbar before Marcelo Brozovic had a goal ruled out by VAR after Keita fouled Dragowski – rushing back to his own goal from a corner – to earn the forward a second yellow and consequent red card.
Inter finished a point above city rival AC Milan in fourth, while Empoli makes an immediate return to Serie B after Genoa's 0-0 draw away at Fiorentina.