Former Bayern Munich winger Ribery created second-half goals for Gaetano Castrovilli and Federico Chiesa as Fiorentina looked set to take the points at San Siro on Saturday, only for Romelu Lukaku and Danilo D'Ambrosio to strike late on.
A dramatic game saw Fiorentina lead early on through Christian Kouame, but Lautaro Martinez scored a majestic equaliser in first-half stoppage time and Inter were in front thanks to a Federico Ceccherini own goal soon after the break.
Ribery then began to run the show, first teeing up Castrovilli after a joyous run down the left, and then when his defence-splitting long pass fed Chiesa.
But with seven minutes remaining, Fiorentina took Ribery off, and Lukaku bundled in an 87th-minute leveller before D'Ambrosio thundered in a back-post header to take all three points
Cristiano Biraghi's cross from the left opened up the home defence and Kouame tapped in from close range after unselfish play from Giacomo Bonaventura.
Inter were awarded an 18th-minute penalty, but the decision was overturned after a video review, with Martinez shown to have been the player who made the first contact when he and Martín Caceres tangled.
Fiorentina were shaken in first-half stoppage time when Martinez ripped a 22-yard strike beyond Bartlomiej Dragowski and into the right corner.
Luck was then on Inter's side in the 51st minute when Martinez's shot from a couple of yards inside the left edge of the penalty area, heading well off target, was deflected in off Ceccherini.
Fiorentina grabbed a sublime equaliser five minutes later, when Ribery's dribbling at speed had Inter's defence backtracking urgently and the Frenchman's short pass released Castrovilli to find the bottom-left corner from 12 yards.
Ribery was at it again in the 63rd minute, roaming through midfield and threading a terrific ball that Chiesa clipped past Samir Handanovic for Fiorentina's third.
Dusan Vlahovic wasted a chance to give Ribery a hat-trick of assists, after the Inter defence were again drawn to the 37-year-old, whose timely release of the ball found his team-mate in yards of space. Vlahovic shot high and wide, and Fiorentina substituted Ribery in the 83rd minute.
Lukaku, who had wasted a string of chances, tucked home new signing Achraf Hakimi’s cross from the right four minutes later.
And it was cruel on Fiorentina when D'Ambrosio headed Inter's fourth a minute later, connecting powerfully with Alexis Sanchez’s deflected cross from the left.
What does it mean?
Maybe if a player is dominating a game, don’t take him off. Ribery was winning the match for Fiorentina, and the decision by Giuseppe Iachini to replace his star man backfired dreadfully.
Perhaps there was an injury but moments before his number was raised Ribery was dancing around, looking for the ball. Inter must have been delighted to see the back of him and won it in his absence.
Persistence pays off
Lukaku put himself about and got into goalscoring positions, but until his late intervention it was a shaky night for the former Manchester United man. While strike partner Martinez caught the eye, and showed why Barcelona have been so keen, Lukaku kept squandering chances.
He had six shots in all and the first four failed to hit the target. Conte would have been delighted to see Lukaku persist, however, and refusing to let his head go down brought about the late equaliser, paving the way for D’Ambrosio to win the game.
Ribery shows no sign of slowing down late in his career. As Inter's defence would concur, his pace down the left flank remains remarkable, and they were standing off, wary of where the next shimmy would take him, before he teed up Castrovilli for Fiorentina's second.
His pass for Chiesa's strike was every bit as impressive, and Vlahovic should have done far better from his chance. Opta recorded five key passes from the veteran, which was two more than any other player on the pitch.
Inter head to Benevento on Wednesday, while Fiorentina play Sampdoria on Friday.