Aqib, who was appointed Pakistan's interim white-ball coach last month, will also take on red-ball coaching duties.
Australian Gillespie was signed by the PCB on a two-year contract in April alongside Gary Kirsten, who resigned as limited-overs coach in October. Gillespie resigned earlier on Thursday amid media reports of a breakdown in relations between him and the PCB.
"Aqib's first assignment as red-ball head coach will be the two-match test series against South Africa during the ongoing all-format tour," the PCB said in a statement.
Pakistan are in South Africa playing a three-match Twenty20 international series followed by three one-day games, before the first Test begins in Centurion on December 26th, and the second in Cape Town on January 3rd.