Jenna Coleman planned to quit Doctor Who last year, according to the show's chief writer Steven Moffat.
The last episode of series eight, Death in Heaven, shows Clara Oswald and the Doctor go their separate ways.
Steven Moffat told Doctor Who magazine that was going to be the end of Clara's journey.
But Jenna later changed her mind and asked if she leave in the Christmas episode instead.
Shortly before recording the Christmas episode, she decided to stay for another series.
Steven said: "She came to the read through... and again changed her mind."
"Frankly, I didn't want to lose her. She's an amazing actress, and she never stops working to make Clara better," he said.
"I was very happy to go the extra mile to make sure we could keep her."
Jenna will return for a third series of adventures with the Doctor in 2015.
It makes her the longest-serving companion in modern Doctor Who, ahead of Karen Gillan and Billie Piper.
The 28-year-old actress from Blackpool said: "I couldn't walk away with the story being unresolved."
The show is due to return to the BBC this autumn.