A goal deep into added-on time from Dejan Lovren edged Liverpool into the Capital One Cup quarter-finals after a dramatic finish which saw the Swans end the game with ten men.
After a goalless first half the game sprung into life after the break as Marvin Emnes' perfect volley gave the Swans the lead, but the drama was yet to come.
After sub Mario Balotelli levelled in the 86th minute, referee Keith Stroud showed Federico Fernandez a straight red card following a challenge on Phillippe Coutinho.
With Anfield pushing them on, the hosts claimed a last-gasp winner through summer signing Lovren, who rose high at the back post to nod home from close range.
The Swans made five changes from the side that beat Leicester at the weekend.
Gerhard Tremmel replaced Lukasz Fabianksi in goal while Jay Fulton and Marvin Emnes came in for Ki Sung-Yueng and Gylfi Sigurdsson in midfield.
Wayne Routledge made way for Nathan Dyer on the right hand side while Bafe Gomis led the attack in place of Wilfried Bony.
Meanwhile, there was a place on the substitutes bench for 22-year-old Modou Barrow, who arrived at the Liberty back in August from Swedish side Ostersunds.
LIVERPOOL: Brad Jones, Javier Manquillo, Dejan Lovren, Kolo Toure, Glen Johnson, Lucas Leiva, Jordan Henderson (capt), Philippe Coutinho, Lazar Markovic (Adam Lallana, 70), Rickie Lambert (Mario Balotelli, 79), Fabio Borini.
SUBS: Simon Mignolet, Javier Moreno, Martin Skrtel, Emre Can, Jordan Rossiter.
SWANS: Gerhard Tremmel, Angel Rangel, Federico Fernandez, Ashley Williams (capt), Neil Taylor, Jay Fulton (Tom Carroll, 88), Jonjo Shelvey, Marvin Emnes, Nathan Dyer (Wayne Routledge, 67), Jefferson Montero, Bafe Gomis (Wilfried Bony, 81).
SUBS: Lukasz Fabianski, Kyle Bartley, Liam Shephard, Modou Barrow.
The hosts started the brighter in this tie, though Lucas' early drive straight at Gerhard Tremmel was the only real threat of the openign 25 minutes.
Brendan Rodgers' side were enjoying the majority of possession and territory, while the visitors were forced to sit back and soak up the pressure.
Lazar Markovic then wasted a glorious opportunity after being teed up by Jordan Henderson, but the winger's effort flew high and wide into the 2,000-strong Swans end.
Former Swans loanee Fabio Borini was the next to probe, the Italian twisting and turning on the edge of the area before directing a curling effort wide of the post.
And Borini was at it again soon after as he latched onto Jonjo Shelvey's loose pass before seeing his powerful low drive palmed wide for a corner by Tremmel.
The Swans's only real threats of the half came near the final few minutes, with Shelvey's free-kick diverted to Nathan Dyer, and shot deflected wide for a corner.
Then, when Dyer was bundled over 20 yards out, up stepped Shelvey and his powerful effort was kept out by keeper Brad Jones.
HALF-TIME: Liverpool 0 Swans 0
The Swans looked brighter after the restart, and Bafe Gomis's header straight at Jones from a Shelvey corner on the hour proved the first real action of the second half.
At the other end, Coutinho fired high and into the Kop after being teed up by Borini before the hosts stunned Anfield in the 66th minute.
Shelvey found himself unmarked some 25 yards out, and when his pass deflected into the path of Neil Taylor, the left-back's looping pass fell to Marvin Emnes, whose thunderous volley on the turn beat the stranded Jones.
Buoyed by their goal, the Swans almost doubled their lead when Montero teed up Emnes just inside the box, but his deflected shot dropped into the hands of the Liverpool keeper.
Garry Monk made his first change immediately after, with Wayne Routledge coming on for Nathan Dyer.
The tempo was picking up, and when Liverpool came forward in their next attack, Glen Johnson's stinging low drive was parried by Tremmel before Taylor reacted first to beat Borini to the loose to clear for a throw.
Tremmel then had to deal with Rickie Lambert's effort before a second Swans change saw Wilfried Bony replacing Gomis.
But Anfield was on its feet with four minutes to go as Liverpool equalised through sub Mario Balotelli, who guided Borini's pinpoint cross past Tremmel from six yards out.
The final Swans change came with two minutes to go as Tom Carroll came on in place of Jay Fulton.
With five minutes of added on time to come, Anfield was poised for a dramatic finale.
And they got it as referee Keith Stroud showed Federico Fernandez a straight red card after a challenge on Coutinho.
And. deep into the allocated time, the hosts got their winner as Dejan Lovren met Coutinho's free-kick deep at the back post and into the net.
Coutinho almost rounded the night off with another goal, but his effort deflected off the boot of Ashley Williams and out for a corner.
And that proved the final act of a dramatic night at the Anfield, with the Swans bowing out of the competition.