Sir Mark Cavendish claimed victory in his final race as a professional cyclist.