Mr Mashaei and ex-president Akbar Hashemi Rafsanjani have been excluded by the Guardian Council, which vets election candidates.
The eight men cleared to stand are all considered conservatives.
The Guardian Council is loyal to Supreme Leader Ayatollah Ali Khamenei.
“In my opinion there will be no problem with the leader [Khamenei] and I will take up this issue until the last moment with him,” Mr Ahmadinejad was quoted as saying on Wednesday.
“I am hopeful the problem will be solved,” he added.
However, Mr Rafsanjani will not contest his disqualification, his campaign manager was quoted as saying.
Mr Rafsanjani, who was president between 1989 and 1997, had been seen as a candidate who could win the support of pro-reform and centrist politicians, whose two leaders from the last election are under house arrest.
The 686 people who registered as candidates were vetted by the Guardian Council, a 12-member body of theologians and jurists.
The candidates they approved are dominated by hardline conservatives with close links to Iran’s ruling clerics.
They include the country’s main nuclear negotiator, Saeed Jalili; former nuclear negotiator Hassan Rohani; former foreign minister Ali Akbar Velayati; and the mayor of Tehran, Mohammad Baqer Qalibaf.
Also approved were Mohsen Rezai, a former head of the powerful Revolutionary Guards; former speaker of parliament Gholamali Haddad-Adel; former nuclear negotiator Hassan Rowhani; former telecommunications minister Mohammad Gharazi; and Mohammad Reza Aref, a former vice-president and technology minister considered the only reformist.
Mr Mashaei is a protege of Mr Ahmadinejad, who is barred under the constitution from seeking re-election on 14 June because he has served two consecutive terms in office.
Known for his controversial religious views, Mr Mashaei has been denounced by hardline clerics as part of a “deviant current” that seeks to undermine Iran’s Islamic system.
The Guardian Council’s spokesman said on Tuesday evening that there was “no provision in the election law for candidates to appeal”.
BBC Iran correspondent James Reynolds says it is now clear that Ayatollah Khamenei did not want either man to disrupt an election he wants to reserve for loyal conservatives.
Many believe it is unlikely that Mr Khamenei will reverse a decision when the Guardian Council was acting on his instructions, our correspondent says.
It is not yet clear what, if anything, Mr Ahmadinejad can do if his appeal to the Supreme Leader fails, he adds.
Millions of Iranians took to the streets to demand a re-run after the last presidential election in June 2009, when the Supreme Leader dismissed claims of widespread fraud by the three defeated candidates.
Two of them, former Prime Minister Mir Hussein Mousavi and the senior cleric, Mehdi Karroubi, became leaders of a nationwide opposition known as the Green Movement, after its signature colour.
They were placed under house arrested in February 2011 when they applied to stage a protest in support of the anti-government uprisings which were sweeping the Arab world. They are still being detained.
Error: No connected account.
Please go to the Instagram Feed settings page to connect an account.