A late header by Benni McCarthy rescued Porto's Champions League campaign and ensured former boss Jose Mourinho made an unhappy return to his former club.
Damien Duff collected Frank Lampard's cross and his resulting shot put Chelsea ahead after 34 minutes.
But Porto came to life in the second half thanks to Diego, who stroked home the equaliser in the 61st minute.
And McCarthy's close-range header, after 86 minutes, consigned Chelsea to their first Champions League defeat.
Despite pre-match security concerns, Mourinho was given a warm welcome by just over 42,000 fans in Portugal.
And the Chelsea boss delved into his strong squad for his return to Porto, making four changes to the side who eased past Newcastle on Saturday.
Alexei Smertin, Scott Parker, Wayne Bridge and Didier Drogba were preferred in place of Claude Makelele, Arjen Robben, Eidur Gudjohnsen and Tiago.
Desperate to carve out the win, Porto seized the initiative in the opening stages.
Diego and Costinha took turns from midfield to try and thread the ball through to South African striker McCarthy.
But it was Chelsea who posed the biggest danger on the break, mainly thanks to Duff's pace down the wing.
After just three minutes, Bridge picked up the Irishman's cross from the right but his shot from 18 yards, with his weaker right foot, just missed the far post.
Lampard combined with Duff on the overlap to feed the ball through to the waiting Drogba after 12 minutes.
But Nuno got down well to his left to push the striker's close-range header onto the crossbar and away to safety.
The Portuguese keeper's fine effort was undone in the 33rd minute when he failed to deal with Duff's left-footed strike.
Duff had capped his fine performance in Portugal with the opening goal
The winger jinked past full-back Pedro Emanuel and fired his shot from just inside the box.
And Nuno only succeeded in clipping the ball with his right hand as it nestled into the bottom corner.
The home side were restricted to set-piece chances as Chelsea slowly drew the sting from the game.
Diego came closest to the equaliser when Petr Cech was forced to punch his free-kick away but Chelsea maintained their lead going into half-time.
Some positive play by Diego suggested Porto might be willing to stage a comeback when his shot in the 58th minute was blocked by Cech.
Two minutes later the 19-year-old Brazilian breached Chelsea's stern defence.
Georgios Seitaridis' shot was cleared by Chelsea skipper John Terry but only as far as Diego, who coolly buried the ball.
The equaliser lifted the tempo of the match but the Premiership leaders quickly took the advantage of the space created by a more urgent Porto.
Drogba forced another good save from Nuno after his trickery took him past Jorge Costa.
The hard-working Lampard was also denied by the Porto keeper in the 72nd minute.
But just when it looked like Chelsea were on course for a predictable win, the home side stole victory with a last-gasp attack.
McCarthy rose above William Gallas in the six-yard box to head home a left-wing
cross from Peixoto in the 86th minute.
His goal ensured Porto's title defence advanced to the knockout stages and saw Mourinho's Chelsea fall to only their second defeat of the season.
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.
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.
Ref: Massimo Busacca (Switzerland).