In "Sword of the Rightful King" by Jane Yolen, the ending is indeed a surprise. The pivotal characters in the book are King Arthur, his knights, and Merlin, the wizard who assists Arthur in his quest to unite the kingdom of Cadbury.
In the final battle, Arthur is mortally wounded, and it appears that he will not survive. However, Merlin reveals that he has a plan to save Arthur's life. He takes Arthur's body to the mystical island of Avalon, where he will be healed by the Lady of the Lake.
After Arthur's departure, the knights of the Round Table are left to rule over Cadbury, but they soon discover that they are not up to the task. The kingdom descends into chaos, and it becomes clear that without Arthur's leadership, Cadbury will not survive.
However, there is a glimmer of hope at the end of the book. In the final scene, a young boy named Gatty appears, claiming to be the rightful king of Cadbury. He presents the sword that Arthur pulled from the stone, proving his claim to the throne.
The book ends with the implication that Gatty will become the new king of Cadbury, fulfilling the prophecy of the sword in the stone. This surprise ending leaves the reader with a sense of hope for the future of Cadbury, despite the loss of Arthur and the chaos that followed his departure.
Overall, the ending of "Sword of the Rightful King" is a fitting conclusion to the story of King Arthur and his quest to unite the kingdom of Cadbury. It offers a surprising twist on the traditional Arthurian legend, while still honoring the themes of leadership, courage, and destiny that have made the legend so enduring.