The annual meeting between the Coppa Italia winners and Serie A champions was played at the King Fahd International Stadium in Riyadh, Saudi Arabia.
"The lads had the perfect approach, we were always sharp and solid. Our first target of the season was to get through to the Champions League knockouts, and the second was this trophy, so it is so pleasing for a coach to see this," Inter manager Simone Inzaghi told Sport Mediaset.
"We remained concentrated, aggressive, and determined, all ingredients you need in a final."
Dimarco scored the first goal after 10 minutes when he ran into the box unmarked and tapped in Nicolo Barella's cross.
Milan's Rafael Leao could have equalised after 16 minutes, but Inter keeper Andre Onana tipped his shot from an acute angle over for a corner.
Inter doubled their advantage after 21 minutes when Dzeko got the ball on the left, wrongfooted Sandro Tonali and fired into the bottom right corner from inside the box.
Milan woke up after the second goal and started to gain possession, forcing Inter onto the defensive but they couldn't find a breakthrough.
Leao managed to get into the box four minutes into the second half, but the Milan striker fired just over the bar.
Martinez wrapped up the win in the 77th minute when he scored with an elegant curled shot with the outside of his left foot.
Milan's best chance of the match came one minute into stoppage time when Ante Rebic's intended cross hit the top of the crossbar.
"I did not expect this, as I know the quality of my players, so I expected a more positive performance," Milan coach Stefano Pioli said after the match.
"At this moment, we are struggling to react to an error, to remain united as a team... the lack of results is starting to weigh on us."
The result marks the first time Inter have won against Milan in an Italian cup final, having lost the Coppa Italia in 1977 and the Italian Super Cup in 2011.