Chambers sent Dale Richards and Narsingh Deonarine back to the pavilion and Ahmed accounted for Simmons, edging a wide delivery to wicketkeeper Foster.
After the morning session had been lost because of overnight rain Chaminda Vaas dismissed Narsingh Deonarine for seven and Dwayne Smith for a duck, both lbw.
They did well to go so close at the Waca after being 68-3 at the start of their run-chase, with Narsingh Deonarine making an excellent 82 in his first Test appearance for four years.
Gayle put on 136 for the opening wicket with Travis Dowlin, who made a more patient 55, before Ramnaresh Sarwan (42 not out) and Narsingh Deonarine (10 not out) guided the tourists through to stumps.
"A few injuries intervened in the series which kind of pushed us onto the back foot, but the guys stepped up and did well with the bat - Shiv (Chanderpaul) didn't play this Test match but Narsingh Deonarine chipped in well and Brendan Nash, " he commented.