The 26-year-old recorded his 10th five-wicket haul in Tests to cap a good day for the tourists, who are looking to win only their third away series.
Bangladesh finished the day on 10-0 despite opener Shadman Islam being dropped by Saud Shakeel off Mir Hamza on the first ball of the innings.
But it was Bangladesh’s bowlers who steered them to a strong position.
Mehidy dismissed Pakistan captain Shan Masood for 57 and opener Saim Ayub for 58 after the home team had been well-placed on 99-1 at lunch.
He produced match-turning figures of 4-21 in Bangladesh’s 10-wicket win in the first Test a week ago, and snared Khurram Shahzad for 12 and then Mohammad Ali and Abrar Ahmed to end the innings with 5-61.
Mehidy was ably assisted by fast bowler Taskin Ahmed, who took 3-57.
Salman Agha, dropped on nought by Zakir Hasan off Shakib Al Hasan, was Taskin’s third wicket after scoring 54 with three boundaries and two sixes.
Bangladesh’s 10-wicket in the first Test last Sunday, also in Rawalpindi, was their first over Pakistan in 14 attempts.
Desperate for a win to level the two-match series, Pakistan started well but lost wickets at regular intervals to slump from a relatively strong 107-1 on a greenish but slow Rawalpindi pitch.