Pakistan built up a solid 174-run lead with eight wickets in hand at stumps on the third day at the National Stadium, with Hafeez on 57 not out and Mohammad Yousuf unbeaten on one.
The home team reached 130-2 when bad light stopped play 15 overs before schedule.
The home batsmen were checked by some tight West Indies bowling after the tourists fought hard to score 260 runs in their first innings, conceding a 44-run lead.
Pakistan lead the series 1-0 after their nine-wicket win in the first Test in Lahore. The second Test ended in a draw at Multan.
Pakistan lost opener Imran Farhat (20) after a slow start to their second innings. Farhat played a rash shot outside the off-stump off paceman Daren Powell and was caught by wicket-keeper Denesh Ramdin.
The West Indies bowled to a tight line and length to keep Pakistan in check as they managed just 61 in the two-hour second session.
But Hafeez and vice-captain Younis Khan continued to stretch the home team's lead in the last session. Hafeez crawled to his fourth Test half-century in 213 minutes, hitting five boundaries.
He added 79 runs for the second wicket with Younis.
The West Indies' fielders - who dropped seven catches in the first two Tests - were once again fumbling as Dwayne Bravo dropped Younis off his own bowling when he was on 19.
Younis, celebrating his 29th birthday, capitalised on the chance, hitting Chris Gayle for the first six of the match before the off-spinner trapped him in front of the wicket with a faster one for 38.
Earlier, Ramdin hit a gritty 50 to keep alive his team's chances of levelling the series. He added 44 runs for the last wicket with Corey Collymore (eight not out) to help West Indies recover from 216-9 to 260 all out.
Ramdin was the last man out after he failed to make the crease at the non-striker's end while attempting a second run. He hit seven boundaries.
Despite dismissing the resolute West Indian opener Daren Ganga (81) early in the day, Pakistan wicket-keeper Kamran Akmal dropped three chances to let the tourists' tail add 69 runs after they resumed at 191-6.
Ramdin held on after Ganga fell in the fifth over of the day. Ganga played a casual shot to an incoming delivery from Abdul Razzaq and was caught by Akmal behind the wicket.
Ganga, who was on 77 overnight, hit nine boundaries during his 304-minute knock.
Pakistan took the second new ball with the West Indies on 213-8 and fast bowler Umar Gul bowled Powell with the second delivery for one to finish with 4-79.
Ramdin, dropped on five by Akmal off leg-spinner Danish Kaneria, took full advantage of the chance and hit Gul for three boundaries before reaching his fourth Test half-century.
The 21-year-old Trinidadian drove well and batted solidly to take the West Indies within 44 runs of Pakistan's first-innings score of 304.
Pakistan 304 and 130 for 2 (Mohammad Hafeez 57 n o, Younis Khan 38; D Powell 1 for 35, Chris Gayle 1 for 23) Vs West Indies 260 (Darren Ganga 81, Denesh Ramdin 50, Gayle 40, Chanderpaul 36; Gul 4 for 79, Kaneria 3 for 62)