The former-Iranian leader, a surprising fan of the late rapper 2Pac, quoted lyrics from the song “Changes” on the anniversary of the founding of the Black Panther Party.
Mr Ahmadinejad said on Twitter: “One of the main objectives of the #BlackPantherParty was feeding the hungry; which did not sit well with the #UnitedStatesGovernment. #BrotherHuey #October15.
“‘It’s time to fight back that’s what Huey said. Two shots in the dark, now Huey’s dead.’”
People reacted on social media with shock at the former statesman’s apparent penchant for gangster rap.
One said: “Ahmedinejad listens to Pac?”
Another said: “This is the strangest timeline.”
And another added: “Un-ironically retweeting Ahmadinejad. Did not expect that one.”
But others blasted the former leader’s decision to join Twitter.
The social media platform was banned under his administration and many Iranians use proxy servers to use it.
One angry Twitter user said: “Are the rest of Iranians allowed to use @Twitter on your country?
Tupac’s parents were active members of the Black Panther members in the late 1960s and early 1970s.
The rapper’s godfather was a high-ranking Black Panther and Tupac himself was named after an 18th-century Peruvian revolutionary “Túpac Amaru II” who was executed after leading an indigenous uprising against Spanish rule.
This ideology influenced Tupac later in life as he joined the Young Communist League USA and his lyrics often dealt with racism and the struggles of the black community.
He was killed in 1996 aged 25 as a result of a drive-by shooting which remains unsolved.
Mahmoud Ahmadinejad was Iranian president from 2005 to 2013.
Mr Ahmadinejad was accused of mass corruption during his reign and other controversies include Holocaust denial and conspiracy theories about George W Bush and Osama Bin Laden being friends.