Kusal Mendis played a crucial hand with the bat before their spinners, led by Prabath Jayasuriya, left Bangladesh on the brink of an innings defeat.