Rail workers have voted to accept a pay deal, ending their involvement in a long-running series of strikes.