Georginio Wijnaldum's third goal of the season helped Liverpool climb back above Manchester City at the top of the Premier League
Liverpool returned to the top of the Premier League but were made to work hard for victory at relegation-threatened Cardiff City.
Jurgen Klopp's side had to be patient as they dominated a dogged Cardiff side, who had chances of their own to cause an upset.
Liverpool made the breakthrough in spectacular fashion, as Georginio Wijnaldum met Trent Alexander-Arnold's low corner with a thunderous first-time effort which threatened to break the net.
The wild celebrations spoke of the visitors' relief, and they had to negotiate some nervy moments, most notably a staggering miss by Cardiff captain Sean Morrison, who miscued a header with the goal at his mercy.
Things then got worse for Morrison, who conceded a penalty after grappling with Mohamed Salah, and substitute James Milner confidently converted the spot-kick to seal victory for the visitors.
Cardiff remain in the relegation zone, three points adrift of safety.
Liverpool, meanwhile, restore their two-point lead at the top of the table over Manchester City, who play their game in hand away at Manchester United on Wednesday.
The Liverpool winning machine marches on
The last time Liverpool were in Wales' capital city in 2014, Luis Suarez scored a hat-trick in a 6-3 thrashing of a Cardiff side managed by Ole Gunnar Solskjaer and destined for relegation.
That chaotic encounter was symptomatic of Liverpool's title challenge that season: thrilling and brimming with goals but also lacking the defensive fortitude of champions.
The Reds ultimately fell short - but this time it has been a different story.
There are still twists and turns to come in this absorbing title race but Liverpool now have the tightest defence in the Premier League.
A record of conceding only 20 goals in 35 games has allowed them to go toe-to-toe with a Manchester City side widely regarded as one of the greatest to have graced this competition.
Liverpool are a solid, patient, winning machine these days - their past five league victories had come thanks to second-half goals, and they had to bide their time here as well.
Klopp's side imposed themselves immediately, monopolising possession and pinning their opponents back in their own half.
Their fabled front three all had chances to score in the first half: Roberto Firmino firing over when clean through on goal, Sadio Mane flicking a first-time effort over and Salah seeing a low shot smothered by Neil Etheridge.
Cardiff, however, were standing firm, with centre-backs Morrison and Bruno Ecuele Manga marshalling a robust defensive display from the hosts.
Liverpool did not panic and eventually engineered a way through their opponents with what seemed to be a pre-planned move, with Alexander-Arnold's low corner steered towards the onrushing Wijnaldum, who swept in an emphatic finish.
Klopp's side had chances to extend their lead - with Jordan Henderson spooning one particularly good one over - but this was another clinical display, Milner's penalty making it nine successive wins in all competitions for the Reds.
Cardiff dig in but fall short
In a season when the battle for Premier League survival has largely seemed a foregone conclusion - with Huddersfield relegated in March and Fulham in early April - Cardiff have been determined to buck the trend.
Written off by many at the start of the campaign, the Bluebirds appeared to be all but down before producing a display of great will and resolve to beat relegation rivals Brighton on Tuesday and revive their hopes of staying up.
Neil Warnock and his players like nothing more than to prove people wrong and, although they were rank outsiders on this occasion, Cardiff were in no mood to simply sit back and admire as their opponents continued to seek a first league title in 29 years.
The home side had to defend deep and in numbers as Liverpool bossed possession and territory; Warnock's charges tenaciously stuck to their task in the face of constant pressure.
Cardiff were not without an attacking threat themselves, with winger Nathaniel Mendez-Laing demonstrating his speed and trickery to beat Alexander-Arnold three times inside the opening half-an-hour.
The Bluebirds were close to taking the lead shortly before the break, with Oumar Niasse - on loan from Everton - athletically hooking towards goal with a volley that was well saved by Alisson.
That gave the home crowd some hope and, even after Liverpool went ahead, Cardiff had their moments.
Only Morrison will know how he managed to miss with a near-open goal at the back post, the centre-back mistiming his dive and seemingly hitting the ball with his back.
His next major involvement was to prove the end of Cardiff's hopes of snatching a point from this game, as he grappled with Salah and conceded the penalty that Milner converted to leave Cardiff three points behind 17th-placed Brighton, with three games to play - one fewer than the Seagulls.
Man of the Match - Joel Matip (Liverpool)Virgil van Dijk has deserved his rave reviews this season but his centre-back partner impressed on this occasion, particularly as he carried the ball out of defence.Record points haul for Liverpool - the stats
Liverpool have now amassed 88 points in the league this season, their best total in a Premier League season; adjusting to three points for a win, they have only earned more in a top-flight campaign in 1978-79 (98) and 1987-88 (90).This was Cardiff City's 10th home league defeat of the season, their most in a single season since 1994-95 in the third tier, when they lost 12 and were relegated.The top six teams have won all 33 of their Premier League matches versus the current bottom three teams in the table this season. This is a top-flight record; surpassing 30 wins in such games in 1891-92, 1978-79, 1985-86, 2001-02, 2011-12 and 2013-14.Liverpool have now won nine consecutive matches in all competitions, their longest winning streak since April 2014 under Brendan Rodgers (also nine games) - a run which also included a victory away at Cardiff.Cardiff have now lost each of their four Premier League matches against Liverpool, conceding 15 goals in all, more than they have against any other opponent in the competition.Georginio Wijnaldum's goal for Liverpool was just his second to be scored away from home in the Premier League, with the other 19 all coming in home games.Trent Alexander-Arnold's assist for Liverpool was his 10th of the season in all competitions, seven of which have come in his past 11 matches.Liverpool have scored more goals via corners (13) than any other side in the Premier League this season, while Cardiff have conceded the most from such scenarios (12).Ten of James Milner's last 12 league goals for Liverpool have come from the penalty spot, with nine of those 12 goals also coming away from home.Only Wilfried Zaha (six) has won more Premier League penalties this season than Liverpool forward Mohamed Salah (five).'We knew we had to stay patient' - what the managers said
Cardiff manager Neil Warnock, speaking to Match of the Day: "As a manager, you cannot ask anything more than what my lads are giving. To hang in as we did for that time, I'm really proud of them.
"We might need two wins and a draw. It's difficult to see where we're going to get a break. I still can't get over [the defeat against] Chelsea. If you saw the dressing room afterwards, I have never seen people destroyed like that.
"The fans have been amazing all season and that helps the manager. They know I am doing my best. We're all trying to punch above our weight."
Liverpool manager Jurgen Klopp, speaking to Match of the Day: "It was prepared to be a proper banana skin and we knew that. The boys were unbelievable. It was clear it was going to be difficult for all of us.
"The weather changed and made it much more intense. We knew we had to stay patient and do the right things. It was very dry on the pitch, so passing was not very easy.
"The boys didn't get frustrated. We had wonderful chances in the first half but we knew if we continued, we would have chances. It was brilliant how we scored the goals."
What's next?
Liverpool welcome Huddersfield to Anfield on Friday (20:00 BST), while Cardiff travel to Fulham the day after (15:00).