Trudeau had been the second-youngest prime minister in Canada’s history when he was elected in 2015, and he had been planning to run for a fourth term in next year’s election even as discontent in his party grew.