Pakistan is four wickets from victory over World Test Championship winner South Africa in the series-opening match.