Teboho Mokoena scored an outstanding free-kick to help send his side through to the quarter-finals of AFCON as South Africa edged past Morocco.