Johannesburg - Pakistan's lower order carried them home as the tourists narrowly edged a South African Invitation XI in a warm-up match in Kimberley on Wednesday.
A recovery built around a patient 35 from 58 balls by Abdur Rehman saw the Pakistanis, chasing 267 runs to win, reaching their target with two balls to spare to secure a narrow one-wicket victory.
The tourists got their innings off to a solid start, with opener Imran Farhat contributing 40 runs before he was run out, and Kamran Akmal making 47 before he was removed by Craig Alexander.
A middle-order collapse, however, forced the tail to put up a fight, with Umar Gul, who made 30, and Shahid Afridi, who smashed a quickfire 29 off 19 balls, chipping in as the tourists reached 270 for nine.
Seamer Hardus Viljoen and spinner Imran Tahir combined well to spearhead a menacing South African attack, but they narrowly failed to pull off a surprise victory.
Viljoen took three for 29 and Tahir grabbed three for 49.
The South Africans had done well to rack up 266 for eight after they won the toss and chose to bat, building their innings around solid top and middle-order partnerships.
Openers Stephen Cook and Quinton de Kock got them off to a great start, combining in a 55-run stand for the first wicket before paceman Gul had skipper Cook caught behind for 34 runs in the ninth over.
De Kock then shared valuable stands of 54 runs with Jonathan Vandiar (24) and 45 with Vaughn van Jaarsveld (36).
The 20-year-old opener made 65 off 73 balls, including six fours and one six, for his fifth one-day half-century, and was eventually removed by Rehman when he gifted a high catch to Younis Khan at mid-off. Temba Bavuma then anchored the middle order with 43 runs off 49 deliveries, combining with Chris Morris (19) in a 54-run partnership for the sixth wicket and Viljoen in a 36-run stand for the seventh wicket.
Viljoen, celebrating his 24th birthday, remained unbeaten on 25.
Rehman took two for 51 to assist in preventing the SA top order from taking control, while fellow spin bowler Shoaib Malik bagged two for 47 to keep pressure on the South Africans.
Pakistan, coming off a 3-0 defeat in the Test series and a 1-0 victory in the T20 series, face South Africa in the first of five one-day internationals in Bloemfontein on Sunday.