Iranian president joins up to three million worshippers in Saudi Arabia.
More than 1.6 million people performed the Hajj this year.
Pilgrims had the choice of three walkways to approach the stone and concrete wall, a modernised version of what used to be a stone pillar.
The ritual represents defiance of the devil and commitment to resisting his temptations.
This year, Mahmoud Ahmadinejad is attending the Hajj at the invitation of Saudi Arabia’s King Abdullah.
His pilgrimage to Islam’s holiest sites is Ahmadinejad’s third visit to the country since taking office.
He visited Mecca in December 2005 for an Organisation of the Islamic Conference (OIC) summit but outside of the Hajj season.
Relations have been rocky between Shia majority Iran and Sunni majority Saudi Arabia, which also has a substantial Shia community in its oil-rich eastern province.
Relations reached an all-time low in July 1987 when 402 people were killed in clashes between Iranians and Saudi security forces during the Hajj.
However, Ahmadinejad’s appearance is seen as a sign of warming relations between the two countries.
Shortly before the Hajj, Iran urged Saudi Arabia to crack down on religious extremism following reports of anti-Shia sermons and pamphlets in the kingdom.