The 32-year-old was omitted from last year's one-day series in India after his performance with both bat and ball slumped.
But Pakistani cricket officials said he would return to the 16-man one-day squad, and he also retained his place in the 15-man squad announced for the Twenty20 internationals.
"We thought that the team needed a spinner to back (Saeed) Ajmal in the one-day series and this could be Afridi's last chance to prove his credentials," chief selector Iqbal Qasim told reporters.
Misbah-ul Haq will lead the team in the one-day matches in Bloemfontein (March 10), Centurion (March 15), Johannesburg (March 17), Durban (March 21) and Benoni (March 24).
Opener Mohammad Hafeez will lead the team in the two Twenty20 matches to be played in Durban on March 1 and in Centurion on March 3.
Paceman Sohail Tanveer is the only omission in the Twenty20 team which toured India, being replaced by another left-arm paceman Wahab Riaz.
"Pakistan's recent one-day showings are good as they have beaten India in India," said Qasim of Pakistan's 2-1 victory in India in January. "I hope they improve their performance from the Tests."
Pakistan have lost the first two of the three Test series, with the final match starting in Centurion on Friday.
All-rounder Abdul Razzaq, dropped after the World Twenty20 in Sri Lanka in October last year, was left out of the side again.
Squad (Twenty20): Mohammad Hafeez (captain), Nasir Jamshed, Shoaib Malik, Kamran Akmal, Shahid Afridi, Saeed Ajmal, Mohammad Irfan, Wahab Riaz, Umar Akmal, Umar Gul, Ahmed Shahzad, Umar Amin, Zulfiqar Babar, Asad Ali, Junaid Khan
Squad (One-day): Misbah-ul Haq (captain), Mohammad Hafeez, Imran Farhat, Nasir Jamshed, Kamran Akmal, Umar Akmal, Shoaib Malik, Shahid Afridi, Asad Shafiq, Younis Khan, Saeed Ajmal, Umar Gul, Wahab Riaz, Abdul Rehman, Mohammad Irfan, Junaid Khan.