The Bluebirds from West Wales and the Bluebirds from the capital city fought out a seven-goal pre-season fixture at New Bridge Meadow.
Both clubs are nicknamed Bluebirds and they fought out a thriller before City netted a last gasp winner.
Haverfordwest led twice, but Cardiff earned the win when James Waite scored his second goal of the match after 90 minutes.
Jake Evans and 17-year-old trialist Tavio Kouakou Almeida, an Ivory Coast national born in France, were the other Cardiff scorers.
French-speaking midfield player Almeida, who has joined Cardiff from Auxerre, also played in the goalless draw against Trefelin BGC when first team defender went to the game and translated for the teenager.
The young Bluebirds from Cardiff played some delightful football during the opening 45 minutes when their movement, passing and awareness were spot on.
City created a series of chances, but could only score once to take a 1-0 lead into the second half.
Trystan Jones had a shot cleared off the line, Ryan Pryce headed against the County bar and James Waite’s fierce drive from distance forced a spectacular one-handed save from goalkeeper Steve Hall.
Keenan Patten also went close with a shot that was deflected away from goal.
Cardiff scored after 15 minutes when Irish playmaker Aaron Bolger darted forward and when defenders closed him down he slipped a square pass to Waite, who fired into the corner.
Head coach Andy Legg’s team should have been more than 1-0 ahead at half-time, but it had been an outstanding team performance.
Bolger caught the eye with his technical ability on the ball, while Waite was energetic and effective in midfield. Centre-forward Shamar Moore led the line with assurance, comfortable receiving the ball with his back to goal and running at defenders.
JD Cymru Championship South team Haverfordwest equalised six minutes after half-time when a cross from the right picked out Marcus Griffiths and he volleyed home from 18 yards.
Worse was to come for Cardiff when County centre-half Scott Tancock, a former Merthyr Town defender, headed past goalkeeper Warren Burwood after 68 minutes.
Jake Evans equalised from a beautifully struck free-kick on 70 minutes, curling his shot round the defensive wall ands into the corner to make it 2-2.
Home team County regained the lead when Jack Wilson netted from close range after 75 minutes before Dalmaida scored City’s third with a clinical finish into the corner from a Waite pass (76 mins).
Haverfordwest County squad for 2019-20: Steve Hall, Ricky Watts, Miles John, Sam Rodon, Sean Pemberton, Scot Tancock, Elliott Thomas, Kurtis Rees, Tom Dyson, Jack Wilson, Marcus Griffiths, Tyler Brock, Ben Fawcett, Kyle Stewart (gk), Jake Merry, Nicky Palmer, Tim Hicks.
Cardiff City u-23: Warren Burwood (Jamie Cogman 80), Ryan Pryce, Daniel Martin (Jake Evans 56), Aaron Bolger, Ben Margetson (William Warnock 46), Trystan Jones, Dan Williams (Jac Davies 56), Keenan Patten (Sion Spence 46), Shamar Moore (Tavio Dalmaida 46), James Waite, Laurence Wootton (Sam Bowen 46). Sub not used: None.