The batsman has not played since June 2016 because of an elbow injury.
The South African's two fours and three sixes in a 44-ball 63 helped his side to 168-5 in their third Twenty20  game against Sri Lanka at Newlands.
However, Sri Lanka hit 170-5 in reply to win by five wickets, despite spin bowler Imran Tahir claiming 3-18.
De Villiers last week ruled himself out of this summer's tour of England.
AB de Villiers hit a 35-ball half-century on his return to international cricket following six months out of action.