"Abdul-Shafi put pen-to-paper on a five-year deal," Zamalek spokesman Sabri Serag said.
Zamalek have been long-term admirers of the talented full back but failed in their attempts to sign him during the past few seasons.
Abdul-Shafi has been also a subject of interest from Zamalek's arch-rivals Ahli after putting in a string of impressive displays with Mahalla.
"I've very happy to have joined Zamalek," the 24-year-old told the club’s official website.
"I finally fulfilled my aim of returning to the club where I enjoyed a fine spell as a youngster."
Abdul-Shafi came through Zamalek's youth ranks before joining Mahalla in 2006.
He is expected to vie with Sabri Rahil for a place in the White Knights' starting line-up.
Abdul-Shafi is the third player to join Zamalek this summer following the arrival of free agent Amir Azmi and Telecom Egypt striker Ahmed Gaafar.