Read Adon Olam on Sefaria for the surrounding biblical/liturgical context.
The hymn is traditionally attributed to Rabbi Shlomo ibn Gabirol (Avicebron, ~1021-1058 CE), the Cordoba-born poet-philosopher who wrote both massive philosophical works (Mekor Chayyim / Fons Vitae) and exquisitely metrical Hebrew poetry. The attribution is uncertain, some scholars argue for Rav Hai Gaon (Baghdad, ~10th c.) or for an anonymous Sephardic poet of the same era. What's certain: the meter and theology fit the Andalusi-Hebrew tradition.
Classical Hebrew poetry (the Psalms) uses parallel meaning-units, not syllable counts. Hebrew liturgy until ~10th c. mostly continued that tradition. The Andalusi poets, Shmuel HaNagid, ibn Gabirol, Yehuda Halevi, invented Hebrew metrical poetry under Arabic influence: strict syllable counts, classical Arabic meters (the qasida patterns) transposed into Hebrew. Adon Olam is one of the small handful of metrical-Hebrew liturgical poems that survived in mainstream prayer. Its predictable meter is what makes the hundreds of melodies possible.
The final stanza ends: "In His hand I deposit my spirit when I sleep and when I wake; and with my spirit, my body too, the LORD is with me, I will not fear." This stanza is recited as the closing line of the Bedtime Shema. Some communities say only this single stanza before sleep; others say the whole hymn.
It is one of the few prayers traditionally sung even by people who don't pray regularly, its melodies are loved enough that secular Israelis at funerals, weddings, and bar mitzvahs will know at least one tune.