Wikipedia explains that the expression refers to “…a metaphorical phrase for a final gesture, effort, or performance before death or retirement.” There are a variety of theories about the origin, but all relate to the fact that swans are believed to sing early in life and are then silent until they sing a beautiful song before they die. Aesop, Socrates, and Aristotle all mention the expression, which had become a proverb by the third century BC. They don’t mention that it refers to retirement, which is the common use today.