AC Milan was made to work for its place in the semi-finals of the Coppa Italia as Carpi produced a spirited second-half performance in a 2-1 defeat at San Siro.
Carlos Bacca scored a flamboyant opener and set up M'Baye Niang for Milan's second, as the home side controlled territory and possession before half-time against the Serie A struggler and looked to be strolling into the last four.
The host's task was made somewhat harder when Matteo Mancosu netted within five minutes of coming off the bench at the break and Carpi – who began the night with only two away wins this season – threatened to make a shock recovery.
Kevin Lasagna failed to make the most of a handful of chances and the visiting frontline was unable to find an equaliser, however, and Milan will now face either Spezia or Alessandria, who face each other in their quarter-final clash on Tuesday.
Cristian Zapata had Milan's first sight of goal in the eighth minute, but the Colombian steered his header wide from Niang's right-wing corner.
Six minutes later, Keisuke Honda's free-kick drew a fine save out of Zeljko Brkic – low to the Carpi goalkeeper's left – after Riccardo Montolivo had been upended by Riccardo Gagliolo 25 yards from goal, but within 60 seconds the visitor's defence had been breached.
A Honda pass played in Bacca, who rounded Brkic and produced a cheeky rabona finish into the empty net to put Milan in front.
Brkic had to be alert to keep out Juraj Kucka's shot in the 18th minute and Zapata's deflected header looped into the relieved goalkeeper's arms midway through the opening period, as Carpi swayed under immense pressure.
Lasagna had the ball in the net for Carpi in the 27th minute, but the striker's effort was chalked off for a blatant push on Zapata, and soon the action returned to the visitor's penalty area.
In the 28th minute, Milan doubled its lead.
Bacca burst down the left and played an excellent pass across the face of goal to Niang, who was left with the simplest of finishes.
Carpi's first attempt on goal came three minutes before the break, when Gagliolo headed wide, as Milan enjoyed a comfortable and dominant lead at half-time.
The visitor came out with renewed enthusiasm after the interval and Lasagna drilled a shot into the midriff of Christian Abbiati, before the flying forward set up substitute Mancosu to give Carpi a lifeline in the 50th minute.
Mancosu, on his club debut after his loan switch from Bologna, was left with an easy tap-in at the back post after Lasagna darted down the right and found his team-mate inside the Milan six-yard box.
Carpi was buoyed and Lasagna wasted a golden chance by shooting wide when his side was three on three with the Milan defence with 20 minutes remaining, as the visitor continued to threaten a comeback.
It took 25 second-half minutes for Milan to renew its examination of Brkic, with Kevin-Prince Boateng and Kucka bringing saves out of the shot-stopper, but their defensive resolve – and Carpi’s wastefulness – ultimately saw it through.