While Ahmadinejad directed most of his attacks at the judiciary, he upped the ante following the sharp devaluation of the rial in past months. It was an odd reminder of his last two years in office, when the national currency tumbled 300% in the aftermath of harsh US and European sanctions targeting oil exports and banking.

His efforts have included videos and speeches during trips to remote provinces, where he still commands popular support among impoverished locals. His attacks on the judiciary and the security services later led some to blame him for the nationwide demonstrations over economic grievances in late December and early January that stunned the political establishment.

The resurgence of his political activism began after the 2017 presidential elections, in which he was disqualified from running by the Guardian Council after ignoring Supreme Leader Ayatollah Ali Khamenei’s public advice to refrain from doing so. The judiciary has picked off his loyalists one by one: Late last year, Ahmadinejad’s Vice President for Executive Affairs Hamid Baghaei stood trial over corruption charges and was sentenced to 15 years in prison . Lamenting the handling of the case, including the judiciary’s refusal to try Baghaei in public, Ahmadinejad has spared no effort in declaring his opposition to the body, including Chief Justice Sadegh Amoli Larijani.

All of this occurred against the backdrop of heightened tension between him and the political establishment. Having stayed silent for most of Rouhani’s first term, he has made harsh public criticism over the past year and is waging a war of words with Iran’s powerful judiciary.

Former Iranian President Mahmoud Ahmadinejad had a busy August. He released a controversial video in which he condemned his successor Hassan Rouhani’s handling of the economy and published an open letter to US President Donald Trump, urging him to release the names of relatives of Iranian officials who hold green cards . He also performed Eid al-Adha prayers among Sunni Iranians in northeastern Golestan province.

In an Aug. 9 video, the former president criticized the Guardian Council for “removing the main candidates” in the 2013 presidential elections in order to guarantee Rouhani’s victory. Notably, his own disputed re-election in 2009 was marred by accusations that the poll had been rigged. In the video, he also the slammed the government’s economic and foreign policies, particularly the Joint Comprehensive Plan of Action, holding all political leaders — from Rouhani to Parliament Speaker Ali Larijani and the chief justice — responsible for the current turmoil, saying, “The economy is on the verge of collapse, public trust in system is near zero, there is rampant poverty and massive dissatisfaction.” The former president then urged his successor to “step down for your own good and the good of our country.”

The political establishment responded to the call for Rouhani’s resignation by tightening the screws on the former president's loyalists. Ahmadinejad’s de facto spokesman, Ali Akbar Javanfekr, was briefly detained and released. The Tehran prosecutor’s office lodged a complaint against Baghaei for insulting high-ranking officials. On July 31, as Baghaei was returning to Evin Prison after a short sick leave, he called the judiciary, Chief Justice Larijani and the Islamic Revolutionary Guard Corps (IRGC) intelligence chief, Hossein Taeb, “cruel” and warned them that the time for “payback” will come.

On Aug. 25, the first court session of Ahmadinejad’s confidant and adviser Esfandiar Rahim Mashaei, who has spent the past six months in administrative detention, was finally held. Mashaei is charged with acting against national security. Ambiguities surrounding the trial, during which he took off his prison shirt and angrily threw it at the prosecutor, have stirred controversy and raised serious questions about the judiciary’s impartiality and respect for the legal rights of defendants.

Hours after the judiciary declared Mashaei’s trial closed on Sept. 2, Ahmadinejad described the proceedings against his former chief of staff in a new video as “a politically motivated show” and slammed the judiciary for “lying and violating laws and regulations in dealing with Mashaei.” He concluded, “With the judge having such a mentality, all officials — from top to bottom — are guilty.”

The former president, whose official website is blocked, continues to use Twitter and the popular app Telegram to put out his messages. Mindful of social media online users who tend to skip long speeches and videos, his messages are often brief and simple, such as “Political reforms will only occur when all segments of society are participating,” and that power and wealth in the hands of the elites will lead to corruption and inequality.

His defiance has put the political establishment in an awkward position and left Ahmadinejad at risk of detention or house arrest.

The fate of the polarizing figure and the role he may play in the future are anyone’s guess. While some analysts believe that his crossing of “red lines” in his criticism of the Islamic Republic will elevate him to a new position in the eyes of the public, other observers argue, “He is merely seeking to prove his political relevance as he is largely ignored by the establishment while lacking support from the street.”

A sociologist at the University of Tehran who spoke on condition of anonymity given the heightened sensitivities surrounding the former president told Al-Monitor, “As there is a risk of more protests and social unrest in the years to come, Ahmadinejad sees himself as the representative of the poor and working masses. These groups usually stand on the sidelines of society, watch the political games and at the same time suffer most from the economic difficulties that are the results of poor decisions by political leaders.” He added, “Nobody sees these people or listens to them, but they are the ones who make important decisions at the crossroads of Iranian history. Ahmadinejad is preparing for that time.”

Every Sunday, judiciary spokesman Gholamhossein Mohseni Ejei holds a press conference. Virtually every week, reporters ask the same question: “Why is Ahmadinejad not being prosecuted?” The answer is always the same: “You will find out someday.”

Some informed sources suggested one explanation to Al-Monitor on condition of anonymity. Despite apparent pressures from the judiciary and IRGC intelligence, Khamenei has so far refrained from ordering Ahmadinejad’s arrest.

For now, it is hard to imagine Ahmadinejad returning to the upper echelons of power in Iran’s political structure. As seen ahead of the 2017 presidential elections, the Guardian Council is unlikely to allow his loyalists to run for office. Still, Ahmadinejad has proven time and again that he is able to change the game, particularly when his foes believe they have him cornered. It is clear that his unpredictability remains his strongest political weapon.