Please correct me if I am wrong, but my understanding is that back then the PM ran the government and the President did not have much power, and then this was changed. Also Supreme Leader was not considered to be part of the government. So, he was in effect the highest ranking person within the so-called elected government.
But the government in Iran is not just the elected part. The non-elected part of the government holds more important keys of the power within the government. The prime minister's role in Iran prior to 1988 was a Chief Operating Officer for just the executive branch, not the government as a whole. Furthermore, Iranian military, army, Sepah, Intelligence (which was not a ministry until 1985) and Judiciary were all outside the executive branch and the PM had absolutely no command or control there. The PM's job was to run the ministries and the huge bureaucracy of the government in the internal day-to-day affairs of the country.
Obviously Khomeini was the top decision maker regarding such affairs as military (including Sepah) and major foreign policy issues. Officially Khamenei as president was the second rank after him, emboldened his position by his special relationship with Sepah (he was Khomeini's long time representative in Sepah). Rafsanjani's position (parliament speaker) was officially the third rank in the country, however he became the main decision maker when Khomeini appointed him as the commander of all war efforts. A quick look at Rafsanjani's memoirs show that major decisions were primarily taken by him and Khamenei, occasionally in consultation with Sepah and judiciary, with very little influence from Ministers or other people from the executive branch.