Muslims turn towards the Kaaba to pray, no matter where they are in the world. The structure is said to have been first erected by Adam and then rebuilt by Abraham 4,000 years ago.
Pilgrims next walk seven times between two stone spots in the mosque.
They then move on to Mina, around five kilometres (three miles) away, ahead of the main rite of the pilgrimage at Mount Arafat.
The climax of the hajj is the gathering on Mount Arafat, about 10 kilometres (six miles) from Mina, where it is believed that the Prophet Mohammed delivered his final sermon.
.
Pilgrims assemble on the 70-metre-high (230-foot) hill and its surrounding plain for hours of prayers and Koran recitals, staying there until the evening.
After sunset they head to Muzdalifah, halfway between Arafat and Mina, where they gather several dozen pebbles so they can perform the symbolic "stoning of the devil".
The last major ritual of the hajj is back at Mina, where pilgrims throw seven stones at each of three huge concrete walls representing Satan.
The ritual is an emulation of Abraham's stoning of the devil at the three spots where it is said Satan tried to dissuade him from obeying God's order to sacrifice his son, Ishmael.
After the first stoning, the Eid al-Adha feast of sacrifice begins, marking the end of the hajj.
The pilgrims can then change back into normal clothing, returning to circumambulate the Kaaba and complete their stone-throwing rituals before heading home.