Some saw Mr Mashaie as a moderate mouthpiece for Mr Ahmadinejad
Iranian President Mahmoud Ahmadinejad has dismissed his most senior vice-president, it has been reported.
The decision, the state news agency Irna said, came after Supreme Leader Ayatollah Ali Khamenei ordered Mr Ahmadinejad to do so.
First Vice-President Esfandiar Rahim Mashaie had angered hardliners last year by saying Iranians and Israelis were friends.
Mr Mashaie no longer considered himself first vice-president, reports said.
The decision came after a week-long stand-off between Ayatollah Khamenei and Mr Ahmadinejad, who had defended Mr Mashaie.
Ayatollah Khamenei wrote to the president, telling him that appointing Mr Mashaie was "against your interest and the interests of the government".
In the letter, which was broadcast on Iranian state TV, Ayatollah Khamenei said: "It is necessary to announce the cancellation of this appointment."
Mr Ahmadinejad, who is known for his own outspoken views against Israel, had been defending Mr Mashaie, at one stage calling him modest and loyal to Iran's Islamic system.
During the day, hundreds of hardline students took to the streets of the capital, Tehran, in support of the demand for Mr Mashaie to stand down.
They had warned they would withdraw support from Mr Ahmadinejad unless he dismissed Mr Mashaie.
During their demonstrations they chanted that defiance of Ayatollah Khamenei's views would not be tolerated, the semi-official Fars news agency reported.
In a resignation letter broadcast on Iranian radio, Mr Mashaie said: "I do not consider myself the first vice-president following the order by the supreme leader and I will offer my services to the dear people anywhere I can."
Ayatollah Khamenei has the final say in matters of state, and analysts say he has rarely faced defiance in the past - though that changed in recent weeks with reformists challenging his ruling that last month's disputed presidential election was fair.
Correspondents say the rift between the ayatollah and Mr Ahmadinejad comes at a precarious time for the president.
They say the president needs hardline support against the reformist opposition who continue to maintain that his re-election was fraudulent.
BBC correspondent Jon Leyne says the row shows how vulnerable Mr Ahmadinejad is to pressure from conservatives.
He says that, although this was a dispute within the conservative camp, the reformist opposition is bound to gather encouragement from seeing those in power engage in such a divisive argument among themselves.
The row over Israel broke out last year when Mr Mashaie, then minister in charge of tourism, was quoted as saying that Iranians were friends with the Israeli people, despite the conflict between their governments.