The victory ended Cardiff's unbeaten start to the season and saw arch-rivals Swansea through to the fourth round of the Carling Cup for the first time in 32 years - and just the third time in history.
Joe Ledley, the only local man on either side, showed how much the occasion had got to him after just five minutes.
After losing the ball the Cardiff midfielder dived wildly into the back of man-of-the-match Leon Britton to pick up the first booking of the match.
The early chances were going the Bluebirds' way, Rae off-balance as he sent a shot wide from Ashley Williams' loosely headed clearance.
Swansea's first opportunity came, improbably, from a long ball, Jason Scotland's knock down finding Gomez.
As the Spaniard fell forward he connected with a spectacular bicycle kick that was comfortably dealt with by Cardiff keeper Enckelman.
Gower was impressive before limping off injured
Jay Bothroyd went close with two chances, first sending a skidding shot just wide after a sharp turn on the edge of the box.
A beautifully placed Rae pass then sent Bothroyd through on goal, keeper Dorus de Vries doing well to deny him with a sprawling low stop.
McPhail picked up the second booking of the night, arriving too late for a challenge on Gomez.
With half-time approaching home fans were lifted by their best chance, good build-up play finding Scotland who turned neatly in the box before firing into the side netting.
A dangerous run from Gower got the Swans rolling after the break, the winger finding Scotland who went down in the box, but with no real suggestion of a penalty.
Gower was then fouled on the edge of the area by McPhail, allowing Gomez to line up the dangerously placed free kick.
As Cardiff's wall charged forward the Spaniard's low, skidding shot struck Rae and slipped past Enckelman's right hand.
The classy Gower limped off to be replaced by Gorka Pintado as Cardiff brought on Peter Whittingham for Ledley.
Another Cardiff subsititute, Ross McCormack, got the ball in the back of the net following a hopeful punt forward from Miguel Comminges, but it was ruled out for offside.
McPhail was given a final warning following another rash tackle, and Cardiff fans held their breath when - minutes later - he slid in to tackle Gomez.
Stephen McPhail shows his despair as he receives the red card
The Irishman looked to have won the ball before bundling over the goal-scorer, but it did not save him from a red card.
The dismissal seemed to shake Swansea's concentration, Bothroyd getting the ball into the net after a McCormack effort went astray, only for the Bluebirds to again be denied by the offside flag.
Cardiff's indiscipline continued, Whittingham booked for a chop at Gomez, McCormack fortunate to escape with a yellow after a wild lunge at the unfortunate Spaniard, and Comminges soon following his team-mates into the book.
Butler slid the ball just wide from the resultant free kick, the winger freeing Gomez superbly for the last chance of the game but the Spaniard blazing high and wide.
The Bluebirds will have their chance of revenge at the Liberty Stadium in the Championship on 9 November, when it will be hoped that there are no repeats of crowd disturbances that spoilt the end of the match.
Swansea manager Roberto Martinez: "I'm very pleased for the fans because we saw what it means and the atmosphere was special.
Cannot play media. Sorry, this media is not available in your territory.
"We kept the ball well, we were patient enough and we played the normal way we play and in that respect it's a big difference.
"This was an important game. It fulfilled all expectations, we know how important it was to get the result.
"It's pleasing but I said it before, everything we do at Swansea City is for the fans
"I'm proud of that atmosphere we had at the Liberty Stadium. I'm sure this is going to be remembered for a long, long time.
"There's been a lot of talk and emotions with the fans (about the derby) and it was a great experience.
"It is something to be proud of in Welsh football."
Cardiff manager Dave Jones: "We are all very disappointed. We let ourselves down.
"We didn't play as well as we can do and Swansea deserved the victory.
"We made too many mistakes and it was our worst performance of the season, we lost our shape and discipline.
"We have no complaints, we should have been better, but we got carried away with the occasion. We spoke about not getting the crowd up but we did."
Bookmark with:
What are these?