The shocking car accident that killed new father Matthew Crawley (Dan Stevens) in the season three “Downton Abbey” finale put fans in a tizzy. How could they?! Just when Matthew and Mary (Michelle Dockery) were happy …

This kind of audience passion comes with the territory, even on an Emmy-nominated drama series. So how do showrunners keep a story on course after it crashes into a tree, so to speak?

Julian Fellowes, who writes all the “Downton” eps, learned that Stevens was leaving the series after season three started filming and five episodes had been written. Not wanting to spend remaining episodes on the slow death of a character, he waited until the season’s final seconds to kill him off.

More exciting for the storyteller is how Matthew’s demise set up season four, which jumps ahead six months.

“A choice we had not made resulted in a narrative spin that was good for the series,” Fellowes says. “We were just going to have Mary and Matthew incredibly happy with baby George. Instead we have a complicated emotional dilemma. Mary has been a widow for half a year. Some people think it is time for her to get over it; others don’t.”

A far less happy couple, the bipolar CIA agent Carrie (Claire Danes) and terrorist Brody (Damien Lewis) of “Homeland,” spurred showrunner Alex Gansa to make his own course correction in season two.

“After the ‘Q&A’ episode, the series changed because Carrie was running Brody as a CIA agent,” Gansa says. “To put these two people on the same side, against the bad guys — we thought that was going to give us more narrative juice than it did.

“We needed somebody else to have a pull on Brody. We needed that tension back.”

So the show brought Abu Nazir — the Al Qaeda terrorist who “turned” Brody — into the U.S., and viewers were left wondering if Brody really planted the season finale’s deadly “second 9/11” bomb.

Game of Thrones” too closed on a bloodbath, but showrunners David Benioff and Dan Weiss knew about the course-change before the series even premiered. They stick closely to the source material: the fantasy novels by George R.R. Martin, who writes one ep per season.

Course changes on “Game” are instead inspired by the cast.

“Time and again, the brilliance of our actors has forced us to reconceive our original notions within scenes, when contemplating seasonal arcs, and even the series arc,” Benioff and Weiss said by email.

Big changes from the books were the relationship between Lannister patriarch Tywin (Charles Dance) and young Arya Stark (Maisie Williams), along with Tyrion Lannister (Peter Dinklage) and his mistress, Shae (Sibel Kekilli).

“Linking Tywin and Arya came not so much out of plot considerations but a hunger to pair two of our favorite actors and watch them spar,” the showrunners say. “Sibel redefined our notion of Shae.”