The longest recognized theme song is "All That Is to Come" by Dream Theater, clocking in at 23 minutes and 8 seconds. It appears on their 2016 concept album The Astonishing and serves as the thematic overture for the entire project.
For context, most TV and film theme songs run under two minutes. This progressive-metal epic is a massive outlier, functioning more like a mini-symphony than a conventional theme.