A final gesture or performance, given before dying. This term derived from the legend that, while they are mute during the rest of their lives, swans sing beautifully and mournfully just before they die. This isn't actually true, swans have a variety of vocal sounds and they don't sing before they die. The legend was known to be false as early as the days of ancient Rome, when Pliny the Elder refuted it in Natural History, AD 77: "Observation shows that the story that the dying swan sings is false."
Poetic imagery proved to be more attractive than science and many poets and playwrights made use of the fable. Shakespeare even used the image in The Merchant of Venice. Portia: "Let music sound while he doth make his choice; then, if he lose, he makes a swan-like end, fading in music."
The actual term 'swan song', seems to have begun in print in the 18th century. The Scottish cleric Jon Willison used the expression in one of his Scripture Songs, 1767, where he refers to "King David's swan-song".
Samuel Taylor Coleridge turned this around in the poem 'On a Volunteer Singer'.
Swans sing before they die; ’twere no bad thing
Did certain persons die before they sing.
Swan-song is now commonly used to refer to performers embarking on farewell tours or final performances.