"The Princess and the Goblin" by George MacDonald is a children's fantasy novel published in 1872. Eight-year-old Princess Irene lives isolated in a mountain castle, unaware that vengeful goblins inhabit the mines below, plotting against the kingdom. When she discovers a mysterious great-great-grandmother in the castle tower and befriends a brave young miner named Curdie, she finds herself drawn into a dangerous conflict. With magical guidance and unexpected courage, they must face an ancient threat emerging from beneath the earth.
Wikipedia page about this book: en.wikipedia.org/wiki/The_Princess_and_the_Goblin Sequel: The Princess and Curdie, #36612, #709. There is an improved edition of this title, eBook #34339