It is also the highest Test score by a Pakistan batsman in Australia and Azhar's highest score against Australia.
He went to lunch on 196 and as the tension built, there was a dramatic end to the first over after the break.
Azhar went for a quick single to keep the strike and Sohail Khan, who starred in the morning session, was too slow.
Nic Maddinson's underarm throw ran him out for 65 from as many balls.
The following over, Azhar scored two to bring up his third Test double century.
Pakistan declared immediately after the fall of the ninth wicket, when Josh Hazlewood had Wahab Riaz caught and bowled for one.
That was Hazlewood's 100th Test wicket and he was the pick of the attack with 3-50 from 32.3 overs, while Jackson Bird took 3-113.
Earlier, Azhar and Sohail gave Pakistan control of the Boxing Day Test with a record seventh-wicket stand for Pakistan against Australia.
Sohail's blistering knock featured four sixes from the bowling of off-spinner Nathan Lyon, who went for 1-115 from 23 overs and is sure to come under intense pressure to retain selection for the third Test in Sydney.
After Sohail smacked successive sixes off Lyon, Dave Warner then could not get hands on a difficult skied chance in the outfield.
Azhar and Sohail, who was recalled for this match, put on 121.
That beat Pakistan's previous seventh-wicket record against Australia of 104, set by Intikhab Alam and Wasim Bari in 1972.
Majid Khan also set Pakistan's previous highest Test score in Australia of 158 the same year.
Another rain delay held up the start of play by 35 minutes and there was a brief break before noon, continuing the wet weather that has dogged this Test so far.
But despite a severe weather warning for much of Victoria, the radar appeared to show a clear stretch through Wednesday afternoon for Melbourne.
Pakistan resumed on 6-310 and Mitchell Starc picked up his first MCG Test wicket when he had Mohammad Amir caught behind for a quickfire 29.
That was also wicketkeeper Matthew Wade's 50th Test dismissal.
- AAP