Mathews was shaping well for his third Test century -- the second in this series -- when he miscued a drive off Junaid and was caught by a diving Ahmed Shehzad for 91 before Sri Lanka reached tea at 359-8.
Debutant Dilruwan Perera had completed his maiden half-century and was batting on 54 with Shaminda Eranga unbeaten on two.
Dilruwan hit Junaid for his seventh boundary to become the 15th Sri Lankan to score a fifty on his Test debut. He has also hit a six during his enterprising knock, supporting his skipper.
Sri Lanka won the second Test in Dubai to take a 1-0 lead after the first Test in Abu Dhabi ended in a draw.
Mathews once again anchored the Sri Lankan batting, defying Pakistan's bowling for six hours on a flat Sharjah stadium pitch which had little for bowlers.