However, he immediately served as the foreign policy adviser to upcoming Chief Martial Law Administrator General Zia-ul-Haq who appointed him as the Foreign Minister shortly after assuming the control of the country. In 1982, after losing General Zia's favour when he made an attempt to keep country on Non-Aligned Movement membership, he lost the foreign affairs ministry to senior military officer Lieutenant-General Yakob Ali Khan. His relationship with General Zia-ul-Haq and his military government further deteriorated, with General Zia complaining about Shahi's speech on improving Pakistan's relations with Soviet Union and the Non-Aligned Movement. He departed from country in 1982 to join the United Nations General Assembly and served as the Chairman of UN Committee on Elimination of Racial Discrimination until 1990, and served as the Chairman of the Pakistan delegation at World Conference on Human Rights. During his last years, he associated with the Institute of Strategic Studies (ISS), Islamabad where he served as its President until his death.