PALLEKELE, Sri Lanka (AP) — David Miller hit five sixes and four boundaries for a career-best 85 not out Friday, lifting South Africa from a precarious state and giving them a total 223-7 in the third one-day international against Sri Lanka.

South Africa must win the match at Pallekele International Stadium to remain in the five-match series after losing the first two in Colombo.

South Africa captain AB de Villiers won the toss and elected to bat first but his batsmen continued their poor form failing to provide a solid start.

Fast bowler Lasith Malinga had opener Alviro Petersen (8) with South Africa on 14. Quinton de Kock, called up for the injured Hashim Amla, made 20 before egding seamer Thisara Perera to Sangakkara.

De Villers scored a patient 47 off 72 deliveries as wickets continued to fall at the other end.

Miller scored 35 runs off the last two overs as he shared 69 runs for the eighth wicket with Ryan McLaren. In the process he bettered his previous best ODI score of 67 against Pakistan.

Spinner Ajantha Mendis broke the visitors' lower middle order, vindicating his selection over seam bowler Shaminda Eranga for the match. He bowled Farhaan Berhardien (2) and Robin Peterson (3) and had de Villers caught by Sangakkara to finish with 3-35.