Prophet Muhammad kept the attack on Mecca a closely guarded secret. However Hatib ibn Abi Balta’ah sent a letter to the Quraysh warning them of the attack. The Prophet was informed of this by revelation and he sent Ali and Zubayr to retrieve it.
The Muslim army eventually marched to Mecca, where they were instructed to spread out and display their numbers. Under the cover of night, Abu Sufyan and two other senior leaders of Quraysh were brought to the Prophet to surrender and were granted amnesty.
Podcast version: podcast.lifeofprophetmuhammad.com