Needing to beat former manager Jose Mourinho's Chelsea to avoid becoming the first holders of the Champions League to fail to progress through the opening group stage, they edged into the final 16 on a nervy night in Portugal.
All the talk heading into the match was of Mourinho's return after walking out on Porto days after they became kings of Europe in May.
And it looked as if their former coach might add insult to injury on his first return to Oporto after Damien Duff put Chelsea ahead in the 34th minute.
Reserve goalkeeper Nuno had already denied Didier Drogba when he clawed a powerful header on to the crossbar minutes earlier.
But the Porto keeper, in the starting line-up for injured regular number one Vitor Baia, showed his inexperience as he gifted Duff and Chelsea the opener.
The Republic of Ireland international cut inside his marker and unleashed a rising left-foot shot which Nuno could only get a weak hand to as it whistled into the back of the net.
Duff was replaced just after half-time by Mourinho who signalled his intent to inflict maximum damage on his former employers by sending on in-form Dutchman Arjen Robben.
But it was Porto who picked up the tempo when Brazilian midfielder Diego unleashed a thunderbolt of a strike which Paulo Ferreira blocked at full stretch.
But the former Porto defender, who Chelsea plundered for £13million in the summer, nor any of his new team-mates could do nothing as the teenager crashed home an equaliser in the 61st minute with a 20-yard strike.
Despite the best efforts of Porto the match looked destined to end in a draw with Chelsea displaying trademark Mourinho discipline at the back in the tense closing stages.
But with four minutes to go, McCarthy rescued Porto after out-jumping William Gallas at the back post and heading Ricardo Quaresma's cross beyond Petr Cech.
Porto: Nuno, Jorge Costa, Pedro Emanuel, Costinha, Luis Fabiano (Postiga 75), Derlei (Quaresma 59), Areias, Diego (Cesar Peixoto 77), Maniche, Seitaridis, McCarthy. Subs Not Used: Rui Sacramento, Ricardo Costa, Pepe, Bosingwa.
Booked: Diego.
Goals: Diego 60, McCarthy 85.
Chelsea: Cech, Gallas, Terry, Ricardo Carvalho, Paulo Ferreira, Smertin (Tiago 65), Lampard, Parker, Bridge, Duff (Robben 54), Drogba (Kezman 77). Subs Not Used: Cudicini, Makelele, Geremi, Gudjohnsen.
Booked: Smertin, Tiago.
Goals: Duff 33.
Att: 42,409.
Ref: Massimo Busacca (Switzerland).