The 38-year-old has managed just 66 runs in seven innings since scoring a hundred against Australia in Dubai last month following his recall to five-day cricket.
The Abu Dhabi Test is Hafeez's 55th since making his debut against Bangladesh in Karachi in 2003. He has so far scored 3,644 runs with 10 centuries and 12 half centuries.
"I feel time is up," said Hafeez. "I am announcing my retirement and feel happy that I worked hard in my career."
A few months back Hafeez had decided to announce his retirement from cricket but wife Nazia and former Pakistan fast bowler Shoaib Akhtar stepped in to persuade him he still had a role to play.