The creator of Suits has said the decision was taken to write Meghan Markle's character out of the TV series as long as a year ago.
Aaron Korsh told Radio 4's Today programme he "took a gamble" on Ms Markle's relationship with Prince Harry working out.
Ms Markle plays lawyer Rachel Zane in the American legal drama.
She confirmed this week that she would leave the show after announcing her engagement to the prince.
'Two people in love'
In the interview, Korsh said: "I knew from a year ago that this relationship was burgeoning.
"And I had a decision to make because I didn't want to intrude and ask her, 'hey what's going on and what are you going to do?'.
"So collectively with the writers, we decided to take a gamble that these two people were in love and it was going to work out."
Korsh added: "What we decided to do (was to) say, 'look, I would rather have good things happen to Meghan in her life' - which would likely mean her leaving the show.
"So let's plan on that and it's much easier to undo that, if it came to it, than to just plan on her staying forever and then finding out she's going to go.
"And the only way to write a character out like that would be if they got hit by a bus or something."
Ms Markle has played the paralegal turned lawyer since the first series of Suits in 2011.
The current series will be her last and - in instance of art imitating life - will show her character marrying boyfriend Mike Ross, played by Patrick J Adams.
After hearing news of the engagement, Adams joked on Twitter he thought his on-screen partner had just popped out for milk.
She said she was just going out to get some milk... https://t.co/y7cnM0eC9D— Patrick J Adams (@halfadams) November 27, 2017
He later posted a glowing tribute to Ms Markle, telling Prince Harry: "Your Royal Highness, you are a lucky man and I know your long life together will be joyful, productive and hilarious. Meghan, so happy for you, friend. Much love."
The royal wedding will take place at Windsor Castle in May.
Asked how he thought Ms Markle would deal with the pressure of royal life, Korsh said: "She is just a natural in front of the camera, and her intelligence and poise... I mean if anyone could handle it I'd say it was Meghan."
On the couple's engagement, he added that "the whole thing is like a fairytale" describing it as "like a dream come true".