After the Iranian revolution, the Shah's government was succeeded by a more or less secular western government. That government allowed the Ayatollah Khomeini to return to Iran from exile and invited him to be the figurehead head of state. He refused. Instead, he started holding court in Qom and setting up Revolutionary Councils under Imams in every Iranian city. These councils became, in effect, a second government parallel to the de jure government. After a year or so, the councils were so popular that they swallowed the secular government. The new constitution kept this bifurcated government intact, so that now Iran has two official governments.
This bifurcated structure has caused the US and the west no end of trouble. The hostage crisis was, from the Iranian point of view, simply part of the power struggle between the secular government and the religious government. It was carried out by the Revolutionary Guard, a quasi-autonomous militia allied with, but not quite answerable to, the religious government. We insisted on negotiating with the secular government, which had no power to end the crisis. The same problem came back to bite us during the Iran/contra scandal and we're still having problems with it today both in Iraq and dealing with the Iranian nuclear program.
No one, including the Iranians, quite knows who is in charge of which program. The person making threats or promises today is not necessarily in a position to deliver. The president himself can be overruled by the Guardian Council or the Supreme Leader, but neither the council nor the leader are in control of the minutia of government. Ahmadinejad probably can't launch a nuclear attack without Ayatollah Khameini's permission, but the Ayatollah almost certainly can't stop the government from working to develop nuclear bombs. To some extent, this is simply clever. It gives the Iranians an artificial but real advantage in negotiations in that it binds the two people in the room into a team who have to craft a sufficiently attractive package to convince the decision-maker who is not in the room and not disposed to being convinced. Good cop/bad cop always works.
But, worse, this dichotomy is also a very real problem in the Iranian government. It not only makes Iran more difficult to deal with, but makes any agreement less reliable. Even the Iranians don't always know who has the authority to make a binding agreement because some other part of the government might decide, on its own and secretly, that the agreement does not apply to it. On matters that are sufficiently important, the only agreement that will last might be the agreement that is imposed.