I believe it acts as an adjective describing the word "time." If the structure of the sentence is changed to:
Long ago, there lived a princess.
I think then it would be an adverb describing "lived."
I would wait for further confirmation on that from someone else, but that's my initial thought.
In the sentence "A long time ago, there lived a beautiful princess," what part of speech is the word "ago"?
2 answers
"a long time ago" is an adverb phrase telling when.