He was born in Syria to a family that was descended from the tribe of Muhammad. His father died when he was young, and he was raised in Mecca by his mother where he learned from the bedouins. When he got older, he moved to Medina and studied under Imam Malik until his teacher's death in 796. Under Imam Malik he took to memorizing the Quran as well as the writings of Malik and also many religious texts.
His status as a student of Imam Malik gave him a good reputation when he moved to Egypt. From Egypt he moved to Baghdad, which was a center of learning at the time, and many came to him to seek knowledge. In Baghdad the Shafi'i school was established by his students who made rulings based on the teachings of Shafi.
Before dying, Imam Shafi was taken prisoner due to political problems by Harun Rashid. However, he was found innocent of the charges against him. He would die in Egypt in 820, he is buried there as well.