Pakistan 198-4 chasing 355 for victory after Brook century put England in strong position
Pakistan started the final session 136-3, and looked on course to go wicketless throughout, which would have potentially made them the slight favourites to claim a huge victory. However, Jack Leach dismissed Imam (60) just before the close of play, which swung the pendulum back towards England.
"We are still in a very good position - a few more wickets would have been great but we are happy where we are," England assistant coach Marcus Trescothick told Sky Sport.
"We have six wickets to go and it is going to be a massive day's play. We have seen most wickets fall in the first session so we hope that continues."
Imam and the impressive Saud Shakeel (54*) put on a classy 108-run partnership, after England's fast bowling trio had bowled some absolute beauties to put the host three wickets down.
Mohammad Rizwan - who opened the batting because Imam was tending to an injury - started well with Abdullah Shafique as they rattled along to 66-0. But in the first over of the second session, James Anderson's absolute ripper bowled the makeshift opener for 30.
Ollie Robinson and Mark Wood also chipped in with stunning inswinging dismissals of captain Babar Azam (1) and Shafique (45) respectively. The quality of all three wickets was of the highest order, with movement on show despite the surface being fairly placid.
Rizwan was still confident Pakistan could level the three-test series.
"We are four wickets down but everyone is hopeful because the pitch is slow and we have good depth in our batting. I hope we can chase these runs," he said.
Earlier, Brook scored a brilliant century (108) that was critical in giving England a big lead, with captain Ben Stokes also making 41 off 51 balls.
The tail did fail to wag for England though, with Robinson (3), Wood (6), Leach (0) and Anderson (4) all skittled out cheaply.
Pakistan spinners Abrar Ahmed and Zahid Mahmood shared seven wickets between them.
Debutant Abrar finished with a match haul of 11 wickets.
England, on their first test tour of Pakistan since 2005, are 1-0 ahead in the three-match series.