League One Brentford twice took the lead as they threatened a major shock, but cup holders Chelsea responded to keep themselves in the competition.
Marcello Trotta, who is on loan from Fulham, gave Brentford a deserved half-time lead only for Oscar to draw Chelsea level with a fine solo effort early in the second half.
Harry Forrester restored Brentford's lead from the penalty spot on 73 minutes after Ross Turnbull brought down Tom Adeyemi.
However, Torres had the final word as his superb curling effort from the edge of the box seven minutes from time spared Chelsea's blushes.
Fit-again John Terry started his first game under Rafa Benitez but it was almost a nightmare return when Turnbull was penalised for clutching his captain's backpass.
Turnbull's refusal to release the ball for a quick indirect free-kick could hardly have been more ironic in the wake of the Eden Hazard saga, Forrester eventually blazing over the crossbar.
Brentford made the breakthrough three minutes before half-time when Adam Forshaw's sliding tackle robbed Frank Lampard and Forrester unleashed a shot Turnbull needlessly parried straight to Trotta, who fired in the rebound.
There was plenty of time for Chelsea to get their act together and it took them only 10 minutes into the second half to do so, Oscar pouncing on a loose clearance and bamboozling the Brentford defence before drilling into the top corner.
But Brentford refused to panic, drawing Chelsea's sting before withdrawing Trotta for Adeyemi with 20 minutes remaining. It was inspired, the substitute winning a penalty almost immediately after being upended by Turnbull after racing on to Clayton Donaldson's brilliant through ball. Turnbull might have seen red but escaped with a booking before Forrester buried the spot-kick right in the bottom-left corner.
Substitute Demba Ba made the difference, challenging for an 83rd-minute ball that fell to Torres, who instinctively curled it into the top corner from 18 yards.
Lampard went close to a winner and Mata appealed furiously for handball in the box against Harlee Dean but that would have been a travesty of justice.