184 runs for the ninth wicket to lift the home team from a precarious 193-8 on the first day.
Their partnership fell just 11 short of the world record ninth-wicket partnership by South African pair Mark Boucher and Pat Symcox against Pakistan in Johannesburg in 1998.
Mahmudullah hit nine boundaries during his almost three-hour stay.
Edwards was the pick of the bowlers with 6-90, his 12th five-wicket haul in Test matches. Sammy chipped in with 3-74.