Kusal Mendis overcame a groin injury to make an unbeaten 74 that paved the way for Sri Lanka to clinch series victory over New Zealand.