Suso cancelled out Icardi's first-half strike to leave the two teams level in the second period, before Inter's captain scored his second of the night in the 63rd minute to send the home side back ahead.
Milan netted their second in the 81st minute through Giacomo Bonaventura, but there was to be a late sting in the tail as Icardi completed his hat-trick from the penalty spot in the 90th minute.
The result has seen Inter move to within two points of Serie A leaders Napoli, while Milan remain down in ninth position after suffering their fourth league defeat of the 2017-18 campaign.
Inter boss Luciano Spalletti made just the one change from the team that started the clash against Benevento before the international break, with the injured Marcelo Brozovic being replaced by Roberto Gagliardini.
As expected, a lively atmosphere saw both sets of players fly into some early challenges, but neither goalkeeper was tested in the opening 10 minutes of action.
It was Inter that had the first real chance of the match in the 13th minute when Antonio Candreva found some space outside the Milan box, and the midfielder's effort crashed against the crossbar.
Milan's first half-chance of the evening came in the 20th minute when Suso worked a yard of space in a forward position, but the attacker's effort was always moving wide of Samir Handanovic's post.
Miranda had Inter's next opportunity in the 23rd minute after rising highest inside the penalty area, but the Brazilian's header dropped just wide as the red-hot atmosphere went up a notch.
Inter made the breakthrough in the 28th minute, however, when Candreva's stunning cross from the right was turned into the bottom corner by Icardi, who took his Serie A tally for the season to seven goals.
Icardi tested Gianluigi Donnarumma with a long-range strike 10 minutes before the break as Inter appeared intent on doubling their advantage before the half-time interval.
Matias Vecino also forced Donnarumma to make a save in the final stages of the first period, before Milan had a couple of excellent chances - Fabio Borini bringing the best out of Handanovic following a low strike, before heading into the side-netting moments later.
Milan boss Vincenzo Montella made an attacking change at the break as Patrick Cutrone was introduced, and the visitors had the ball in the back of the Inter net in the 49th minute when Mateo Musacchio converted after Silva had hit the post, but the offside flag was raised.
Suso and Borini then both had efforts from distance in the period that followed, but Handanovic denied the pair as Inter kept their one-goal lead intact in the early stages of the second half.
Cutrone was next to come close for Milan in the 54th minute, with the substitute just missing the Inter post after meeting a super cross from Ricardo Rodriguez.
The equaliser was coming, however, and it arrived in the 56th minute when Suso found some space outside the Inter box before curling a sensational effort into the bottom corner of the net.
Inter should have regained the lead less than five minutes later when Candreva found Vecino just inside the Milan box, but the midfielder sent his effort just wide of the post. Milan then had a super chance down the other end, with Bonaventura seeing his close-range effort kept out by Handanovic.
It was Inter that scored the game's third goal in the 63rd minute, however, when Icardi produced a stunning volley from a Perisic cross, which took the Argentine forward to eight league goals for the campaign.
Both teams had half-chances in the 15-minute period that followed, but the Milan derby headed for its final 10 minutes at 2-1 Inter.
Milan pegged the home side back once again in the 81st minute when Bonaventura turned home Borini's cross at the far post, with Handanovic simply unable to prevent the ball from trickling over the line.
Rodriguez then sent one wide of the Inter post, before Eder had a goal-bound strike blocked down the other end as both teams looked for a winner.
It came for Inter in the most dramatic of circumstances, however, with Icardi pulled to the ground by Rodriguez inside the penalty box. The 24-year-old stepped up to find the bottom corner from the penalty spot in the 90th minute as he netted a famous derby hat-trick, piling more misery on Milan in the process.