Lukaku headed home a minute before the end of extra time in Florence, just as it appeared as if the match was heading for penalties.
The score was 1-1 at the end of regular time after Fiorentina’s Christian Kouam cancelled out Arturo Vidal’s opener from the penalty spot.
Inter will be the home side when it plays its city rival at the end of the month. The two Milan teams are also leading Serie A with the Rossoneri top of the league, three points ahead of second-place Inter.
Juventus hosts Genoa later in the Italian Cup and Napoli welcomes second-division Empoli.
Fiorentina is dangerously close to the relegation zone in Serie A but it took the Nerazzurri until five minutes before halftime to break the deadlock.
Christian Eriksen’s effort was parried by Pietro Terracciano. Alexis Sanchez hit the post with the follow-up but the Fiorentina goalkeeper had brought down the Chilean striker as he unleashed his shot and the referee pointed to the spot.
Vidal then hit the penalty down the middle for his first goal for Inter.
Fiorentina was awarded a penalty of its own moments later when Milan Skriniar appeared to foul Kouam but the referee reversed his decision after a video review.
The hosts did equalize in the 57th minute. In a goalmouth scramble, the ball eventually fell to Kouam who had time to control it before blasting into the top right corner.
Lukaku had been rested but he was brought on in the 69th and, moments after seeing a great chance well saved by Terracciano, Inters star forward scored the winner, heading in Nicol Barella’s cross from the right.