The poem is sung by Bilbo Baggins at the Grey Havens, as he is about to leave Middle-earth forever. Chronologically this places it at the very end of The Return of the King, the last book of The Lord of the Rings, although it was written later than the books and never included in them.
The song is included in the BBC Radio 4 adaptation of The Lord of the Rings (1981), with music by Stephen Oliver. The first verse is chanted by John Le Mesurier as Bilbo, the second omitted, and the third sung by a boy soprano.
There is no reference to the song in the theatrical version of Peter Jackson's The Lord of the Rings: The Return of the King (2003). It is not impossible that it could be included in the extended video and DVD version scheduled for 2004, but it seems unlikely. The movie's closing credits are accompanied by the song "Into the West", sung by Annie Lennox, which has a similar emotional resonance.