De Villiers' initial stint finished with a victory against Surrey last week, but he will return to the club for the final two games of the group stage, and the knockouts if Middlesex qualify.
Hafeez will also be available for those two games, with Mujeeb Ur Rahman, the club's other overseas signing, set to return to Afghanistan after being recalled by his board.
Hafeez has been playing in the Global T20 Canada - he hit 85 runs in five innings for Edmonton Royals - and is expected to be available for Wednesday's game at Essex.
This will be Hafeez's first stint in county cricket, though he did play club cricket in the Liverpool League in 2004 and 2005.
Hafeez retired from Test cricket in December, but remains available for white-ball internationals.
He was part of Pakistan's World Cup squad, making 253 runs including a vital 84 against England at Trent Bridge, but was left off their central contracts list last week.
After reaching the knockouts once in the last ten seasons, Middlesex have had an impressive campaign, and sit second in the South Group with five games to play.
De Villiers' shoes will be difficult to fill: in five innings for the club, he made 253 runs, striking at 191.66, including two scores of 88 not out and a 40-ball 64 to sign off against Surrey.
1600 BST, August 13 - This story was updated to include news of Mujeeb's availability