|World Cup warm-up, Bristol|
|Pakistan 262 (47.5 overs): Babar 112, Malik 44, Nabi 3-46|
|Afghanistan 263-7 (49.4 overs): Hashmatullah 74*, Hazratullah 49, Wahab 3-46|
|Afghanistan won by three wickets (Scorecard)|
|Other World Cup warm-up, Cardiff: South Africa 338-7 (50 overs) beat Sri Lanka 251 all out (42.3 overs) by 87 runs (Scorecard)|
Afghanistan beat Pakistan by three wickets in a World Cup warm-up match at Bristol featuring an unbeaten 74 from Hashmatullah Shahidi.
Opener Hazratullah Zazai hit 49 and Mohammad Nabi added 34 to see Afghanistan to victory.
Earlier, Nabi took 3-46 as Pakistan were bowled out for 262 despite a century from Babar Azam.
In the other World Cup warm-up match, South Africa beat Sri Lanka by 87 runs in Cardiff.
Proteas skipper Faf du Plessis top-scored with 88, ably supported by Hashim Amla (65) in a partnership worth 128 for the second wicket following the early dismissal of Aiden Markram for 21.
After both fell in successive overs, Rassie van der Dussen (40) and Andile Phehlukwayo (35) hit close to a run a ball to help South Africa reach 338-7.
Sri Lanka batsman Avishka Fernando had to be carried off on a stretcher when he was injured while fielding in the covers. However, he is still expected to be fit for the World Cup after scans revealed he had suffered only a minor ankle injury.
Sri Lanka began poorly in reply and were reduced to 10-2 inside three overs thanks to two wickets from Lungi Ngidi (2-12).
Dimuth Karunaratne (87) and Angelo Mathews (64) showed resistance but Phehlukwayo took 4-36 to help bowl out Sri Lanka inside 43 overs.
South Africa face West Indies in their second warm-up game at Bristol on Sunday before opening the tournament against hosts England on 30 May.
Sri Lanka meanwhile take on Australia in their final warm-up game at Southampton on Monday before their World Cup opener against New Zealand in Cardiff on Saturday 1 June.
- World Cup schedule - who's playing who, when and where
- The Cricket World Cup's 10 greatest matches
- CWC 6 days to go: The captains' podcast
At Bristol, Babar top-scored with 112 to help lead the recovery after Pakistan were reduced to 65-3 early on.
His 102-run partnership with Shoaib Malik anchored the innings but Malik's eventual dismissal for 44 sparked a collapse, with Pakistan losing their final five wickets for 42 runs.
Afghanistan made a fine start with the bat and were 45-0 after six overs before opener Mohammed Shahzad retired hurt with a hamstring injury.
Some tight bowling from Imad Wasim (2-29) restricted runs in the middle overs. Wahab Riaz (3-46) then took two wickets in the 48th over to give Pakistan hope of victory, but Hashmatullah and Rashid Khan saw Afghanistan home with two balls to spare.
Afghanistan face England at The Oval in their final warm-up game on Monday before their World Cup opener against holders Australia on Saturday, 1 June.
Pakistan meanwhile play Bangladesh in Cardiff on Sunday before taking on West Indies at Trent Bridge in their first World Cup match on Friday, 31 May.
'Work to do for Pakistan'
Analysis by Test Match Special's Scott Read
Babar Azam continued his impressive start to his tour of England with an impressive century but it wasn't enough for Pakistan who are still looking for their first win in England this year.
Afghanistan will leave Bristol for their next warm-up match against England at The Oval on the back of an encouraging performance.
With an impressive spin attack they took the final five wickets for just 42 runs, led by Mujeeb Rahman who opened up the bowling before they unleashed Rashid Khan who fired in some rapid leg-spinners which have the potential of lighting up the World Cup.
The run-chase was anchored superbly by Hashmattullah. On the evidence of today there is work to do for Pakistan ahead of the competition starting.