The Black Cats were within nine minutes of being dumped out of the competition by League One Northampton, who took a 2-0 lead at the Stadium of Light to silence the bulk of a crowd of 21,082.
But after Colin Larkin and Luke Guttridge had fired the Cobblers to within touching distance of a famous victory to add to their win over Bolton in the last round, Keane's men launched another remarkable comeback.
Substitute Anthony Stokes struck after 85 minutes and then again in the third minute of injury time to take the tie into extra time.
When the additional 30 minutes failed to produce a winner, keeper Marton Fulop kept out Leon Constantine's spot-kick to seal a 4-3 shoot-out victory.
However, Keane was not a happy man.
He said: "I had a feeling this morning, I just thought everyone thought we were going to turn up and win the game of football.
"Our players certainly did, I think our supporters did.
"It was probably one of the worst and longest nights I have ever had in my football career. It was a shambles.
"I hope the team is a reflection of myself, but the players automatically think they are going to win a game of football.
"From the start, it was walking pace, nobody sprinting, the passing was awful, nobody was prepared to run off the ball, supporters booing everybody, abusing me towards the end.
"It was just a bad, bad night, I have to say, one of the longest nights I have had in my football career.
"If anyone is brave enough to say, 'Well, you are in the next round', good luck to them."
Keane's anger was well-founded after his much-changed side - only three of the men who started Saturday's 2-0 Barclays Premier League win over Middlesbrough were retained - laboured through the bulk of normal time.
Larkin's 20th-minute opener was not against the run of play, and although Northampton keeper Frank Fielding had to pull off excellent saves to deny David Healy and Dean Whitehead before the break, the visitors were good value for their half-time lead.
Despite the introduction of derby hero Michael Chopra and Kieran Richardson at the start of the second half, the Wearsiders were little improved, and the game looked to be over when the excellent Guttridge converted Larkin's 81st-minute cross.
However, with Nyron Nosworthy having limped off with a suspected torn hamstring, Stokes nipped in for what looked like a consolation strike five minutes from time, and then crashed in a header off the underside of the bar with literally seconds left to play.
Asked what his overriding emotion was, Keane said: "It's not relief, it is anger, frustration, disappointment. I could think of a few harsher words, but you wouldn't be able to print them."
Keane was unhappy too, with some sections of the home crowd, who turned on him and his side as things went from bad to worse.
He said: "In football, everyone has short memories. There was some idiot about three or four weeks ago as well.
"But you remember these things. You shouldn't - we have got plenty of brilliant supporters - but you always remember the idiots."
Cobblers boss Stuart Gray, like Keane, a former Nottingham Forest player under Brian Clough, was philosophical in defeat.
He said: "I am proud of my team, very proud of my players.
"I often say to the players, a game lasts for 95 minutes, but to be so close to knocking another Premier League team out...
"But I have been in the game long enough to know. I worked for a manager who said it only takes a second to score a goal. They scored in the 85th and the 92nd."
Sporting Life