Hafeez finished with 80 not out for his ninth Test half-century, his first in 11 innings, while Ahmed Shehzad notched his maiden fifty on his debut as Pakistan, set 302 runs in a possible of 67 overs, finished on 158-2.
The draw left the three-Test series open, with the second Test starting in Dubai on Wednesday. The third Test will be played in Sharjah from January 16.
The no-result is also a moral victory for the Sri Lankans who were in a danger of losing after conceding a big 179-run lead in the first innings and were 186-4 after the third day, leading by just seven runs with six wickets intact.
The Man of the Match title was awarded to Sri Lankan skipper Angelo Mathews, who hit a career-best 157 not out to pull his team out of danger on the fourth day when they lost only one wicket in the full day's play for 234 runs.
The target always looked beyond Pakistan's reach as their best winning chase in all Test cricket was 314 against Australia in Karachi in 1994.
Pakistan lost opener Khurram Manzoor early, caught behind off paceman Suranga Lakmal after scoring eight, but Hafeez and Shehzad avoided any further loss and put on 94 in an unbroken second wicket stand.
Hafeez reached his half-century with two fours in one Sachitra Senanayake over. He had been dropped from the Pakistan team for the two-Test series against South Africa, also in Abu Dhabi, in October, after scoring just 113 in 11 innings.
Shehzad also hit spinner Rangana Herath for his seventh four to reach his maiden 50 before he was trapped leg-before by the same bowler soon after tea for 55.
Hafeez hit 11 fours during his sedate knock. Younis Khan was the other unbeaten batsman with 13.
Mathews said he was happy with his team's fightback.
"Pretty happy with the result and hope to continue like this in the series," said Mathews, named man-of-the-match.
"We were in a spot of bother after the third day but I am happy that we came good in batting and forced a draw."
Pakistan captain Misbah-ul Haq was disappointed at his side's batting collapse in the first innings.
"It was a pretty even match. We dominated the first three days but they came back strongly," said Misbah, who also scored a century in the match.
"We need to improve our batting because the way we lost six wickets for 50-odd runs was not good and also our bowling when the wicket is not conducive."
Earlier, Sri Lanka declared their second innings on 480-5 after batting an hour and 30 minutes but their slow batting showed they had saftey on their minds rather than forcing a lead in the three-Test series.
It was the unfinished sixth wicket 156-run stand between Mathews and Prasanna Jayawardene (63 not out) that continued on the fifth day and ended all hopes of a Pakistani win.
Mathews batted for 457 minutes, hit 16 fours and a six in an extraordinary display of patience and fight.
Prasanna's 169-ball knock had six fours and a six.
Pacemen Junaid Khan finished with 3-93, while Bilawal Bhatti took 2-146.
Off-spinner Saeed Ajmal, who took 18 wickets in Pakistan's 1-0 win over Sri Lanka in 2011, finished wicket-less in his 49 overs, conceding 115 runs -- only the fifth time that he failed to get a wicket in an innings in his 31 Tests.
Scores
Sri Lanka 204 and 480/5 declared
Pakistan 383 and 158/2
Result: Match Drawn
COMMENTS (2)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ
I wonder why Pakistan had no guts to try and win the test. Just proved that we have a mediocre Captain with less-than-average talent. No wonder we are not in top 3 sides.