The Guyanese pairing of Sarwan (102) and Shivnarine Chanderpaul (86 not out) put on 157 for the fourth wicket after West Indies, chasing a target of 253, were in trouble at 73 for three.
The win means West Indies have ended their losing streak of seven consecutive Test series and foils Sri Lanka's hopes of a first series win in the Caribbean.
Sarwan and Chanderpaul turned the innings around with a display of patient and considered batting which was exactly what was required at a delicate stage of an absorbing Test match.
Sri Lanka had pinned their hopes on a breakthrough with the new ball and that was delivered when Tillakaratne Dilshan took a superb catch to dismiss West Indies' captain Chris Gayle for 10 when the left-hander tried an ambitious drive off a full-length Thilan Thushara delivery.
The Guyanese pair of Sarwan and Chanderpaul batted throughout the afternoon session, taking few chances and utilising some smart running between the wickets.
SRI LANKA (I Innings) 278
WEST INDIES (I Innings) 294
SRI LANKA (II Innings) 268
WEST INDIES (II Innings)
Gayle c Dilshan b Thushara 10
Chattergoon lbw Vaas 11
Sarwan c Dilshan b M’tharan 102
Samuels c Warnapura b Vaas 11
Chanderpaul (not out) 86
Smith (not out) 14
Extras (B-11, LB-2, W-2, NB-5) 20
Total (for 4 wkts, 68.3 overs) 254
Fall of wickets: 1-23, 2-24, 3-73, 4-230
Bowling: Chaminda Vaas 17-2-52-2, Mirando Thushara 12-3-49-1, Ishara Amerasinghe 13-0-43-0, Muthiah Muralitharan 24.3-4-92-1, Chamara Silva 2-0-5-0.