He served as the 6th and last Prime Minister of the country from 15 March 1989 to 31 August 1991. Masheke became Prime Minister when the previous Prime Minister Kebby Musokotwane was removed and given an overseas diplomatic post as then-President Kenneth Kaunda believed that Musokotwane was aiming to replace him and take over Zambia as the next President. The role was abolished in 1991 when Zambia adopted a new Constitution owing to discussions between United National Independence Party (the only legal polictial party in Zambia at the time) and Movement for Multi-Party Democracy (an opposition party) to allow for multi-party elections to be held later the same year.
The powers that Prime Minister Masheke had were subsumed back into the office of President starting from after the new President was elected in the 1991 Zambian general election. The Constitution also allowed Masheke remain Prime Minister for the period in-between the adoption of the Constitution and the general election. According to Masheke in an interview with Zambian media in 2018, at the time the title was abolished, he was paid less as Prime Minister than he paid his private secretary.