"One of the things that we figured [viewers] would least expect was a little hope at the end of it all — so that's what we chose to go with."

[This story contains spoilers from the series finale of Showtime's Homeland.]

Homeland wrapped its eight-season run Sunday night, delivering a bloody payoff to the tension that had been mounting over the final episodes — though not the one that many viewers might have had in mind.

In a last-ditch effort to prevent a nuclear conflict between the United States and Pakistan, Carrie Mathison (Claire Danes) hands over longtime mentor and friend Saul Berenson (Mandy Patinkin) to Russian spies. In exchange for the identity of his longtime Russian asset, they promise to release the black box recording that proves a mechanical malfunction, not the Taliban, caused the Black Hawk helicopter crash that killed the American and Afghan presidents. Saul's unsurprising refusal, however, does not end in his murder. Carrie discovers the identity of his source, a U.N. Russian translator who is outed and chooses to shoot herself just before capture. War is avoided. But Carrie essentially becomes the turned agent she's been suspected of being all season and flees a traitor with Russian GRU officer Yevgeny (Costa Ronin).

Skipping ahead two years down the line, a coda reveals Carrie and Yevgeny living together in a luxe Moscow penthouse. She's published a book about her decision to betray America for Russia. And as the pair head out for a night on the town, Saul is seen receiving a copy of her memoir — discovering a message in its spine. In Moscow, Carrie discretely trades purses with a woman in the ladies room of an old concert hall. In Washington, Saul reads the warm note containing Russian intelligence with the promise of more to come. Carrie, branded a traitor in her homeland like Nicholas Brody (Damian Lewis) before her, is now America's only asset in the inner circle of Russian intelligence.

Homeland co-creator and showrunner Alex Gansa, who wrote the episode with co-creator Howard Gordon, spoke with THR earlier in the week about the bittersweet and relatively optimistic manner in which he chose to end his Showtime series, as well as the storytelling possibilities built into that final twist and what he hopes the show says about America and its position in the world today.

So what's it been like ending the biggest chapter of your career alone in your house?

What's really interesting is people have been saying that they've now turned to Homeland to escape anxiety. I think it's the first time I've ever heard Homeland being used as a de-stressor in the world.

Terrorism is the new comfort viewing. How do you feel about this episode finally being out in the world?

I have been so anxious and nervous, as we all have been, just trying to end the thing with some sort of grace — to make it feel meaningful for all the people that have stuck with the show for so long. It was really a struggle.

There’'s an increasing amount of pressure on this idea that series need to "stick the landing" at the risk of tarnishing what came before it.

Not only that. You're at the end of a run — whether it's six years, eight years, whatever — everybody is also so exhausted. Emotions are just bubbling under the surface, and everybody feels so proprietary about the show. Everybody has opinions, and there are disagreements. It was really hard to navigate the last couple of episodes and where we wound up. It's a conversation you're having with people that you love who all have different ideas about where it should end and what message we should be putting out into the world.

What did you and Howard Gordon, in your conversations, most debate about how to wrap things up?

The age-old question at the end is: Do your characters survive? And if they do survive, how do they survive and what state of mind are they in at the end? Those were the conversations that not only Howard and I were having — but that we were all having as a writing staff, as a troupe of actors and with Lesli [Linka Glatter, directing EP]. We talked a lot about what people would expect from a Homeland finale. One of the things that we figured they would least expect was a little hope at the end of it all, so that's what we chose to go with. Carrie obviously has blood on her hands, but she's found some sort of peace and belonging in the place where she is. It took a lot of trial and error to get to that place.

Did you give serious consideration to killing off either Carrie or Saul?

It was on the table, for sure. You tend to talk about the ending all the way through a season in the story room, so you're constantly throwing out ideas and seeing if they stick as you move through the series, breaking the season. As we got closer to the end, I think the idea that either Saul or Carrie would die became more and more remote.

Was there a point where you realized you were writing toward this specific ending of Carrie, ostensibly a traitor, working as an American asset in Russia?

We did want to put her in a place where it felt like she belonged, and, if not redeem, we wanted to repair the relationship with Saul a little bit. The idea was to cleave them apart in the most dramatic way possible and then to dramatize at the very end that first gesture of hers back to him. That gesture is, "Look, I know I destroyed somebody important in your life. I know that the asset was so important to national security that I am going to take that asset's place." That is the small gift that she gives back to Saul on the beginning of a relationship that will be repaired in our audience's imagination after the series.

You told me last year that you and Claire disagreed about one story point at the end of the season. Can you say what that was?

I'd really rather not. It was a really difficult conversation, and we had very different ideas and opinions about it. But, as is the case in all great partnerships, we came up with a third idea that was better than the two we were arguing for. That just speaks to the process that we all have built together over the last 10 years and eight seasons.

What was the most challenging scene to film in the finale?

The whole sequence that begins when Carrie comes back to Saul's house, when she's got the kill team sitting outside. Even Carrie herself has no idea where that is going to go. Those scenes in the study and then upstairs in the bedrooms were the most emotional ones that we had shot in a long time. That was also the last Carrie/Saul scene ever shot. It was an incredibly emotional moment. Claire and Mandy, these two fantastic actors and great friends, were just in each other's arms sobbing for 15 minutes.

It is so bizarre, after a decade of globe-trotting and filming on the East Coast, you had to film the finale in Los Angeles.

It's just crazy. We had to. We couldn't accomplish what we thought we could accomplish in Morocco. We were sure we were going to be there all season, but there was just no way that we could accomplish what we needed from earlier episodes, all that military stuff. So that also influenced how the season ended. Imagine if the season had ended in Afghanistan. We'd have a different ending entirely. Sometimes these things turn out to be fortuitous. But it was a real shocker that we were all in Los Angeles, trying to find locations that looked like Moscow or Afghanistan. It was intense. God, it took us so long to make this last season. I mean, it took us forever.

Compared to most of the previous seasons, where you were shooting down to the wire.

We had so much time. When we first sat down to discuss the season, we must have spent the first month and a half trying to tell a story in Israel. We thought we were going to do a story with Carrie and Saul and deal with the whole Israeli-Palestinian problem. We just couldn't figure it out, so we had to switch gears.

Did you feel it was important to start the episode with the clip of Damian Lewis as Brody?

That was not scripted. That was created in the editing room as a way of trying to locate Carrie, emotionally, at the beginning of the episode. It was actually done because we didn't have enough money to shoot a scene that had been scripted in that place. I just thought that the callback was fairly effective, in terms of really finally putting Carrie in Brody's shoes — with the prospect of doing something incredibly ugly for the best of all reasons.

The show reinvented itself so many times, it's almost like seeing a clip from another series.

A complete reinvention. It's so great to see Damian's face, I have to say. [Laughs.] He is still very much a part of the family, and we're all in touch with him. It was just nice to bring him back and to show him again because he was such a vitally important part of the beginning of the whole thing.

Some finales go for absolute closure, but this one opens up the possibility for so much more storytelling. Is that the kind of ending you prefer?

One of our big thoughts too was allowing these characters to live on in the imaginations of our fans. There is comfort in this, because the story doesn't end. It closes, but it doesn't end. Carrie and Saul's life continues, more in our audience's minds than it ever is going to live in a film or another season. I don't think that's going to happen. It might. It does leave open that possibility, obviously.

You've spoken a lot about how Homeland interrogated the American response to Sept. 11. And very early in this season, you pivoted to an inexperienced president being leaned toward war as a quick fix to an international dilemma. What did you want to say about the America we're living in today with this season?

If we had a more global message, it was to try to dramatize what a precarious position we are in. An accident or a misinterpretation of an event, or another actual attack on the homeland, could bring us to our knees in a way. With leadership that is either inexperienced or misguided, that becomes even a greater possibility. Those were the kind of messages that we were sending out into the world — or at least were trying to. And in this particular season, the worst case didn't happen, which might also be unexpected in a Homeland way. But President Hayes [Sam Trammell] actually does the right thing at the end. It just takes him a long time to get there. There is a little bit of hope in that, too. It all comes down to the dedicated professionals like Carrie and Saul to prevent something like that happening. Clearly, that's what Carrie has been working toward the entire season.

It's funny that you cast Claire’s husband, Hugh Dancy, as the ultimate S.O.B. of the season — the character pushing the president toward war.

That haircut and that beard that doesn't meet his sideburns! [Laughs.] He is just such a despicable character in the best way. There is one shot in the finale when Saul is telling him about the black box, and the fact that nobody shot down the Black Hawk, and we stayed on Hugh's face for like a minute. The emotions that were playing across his face were so repulsive and so riveting to watch.

Speaking of casting, I love that you got Kamasi Washington in there at the end to call back to the show's relationship with jazz.

I was introduced to Kamasi Washington at the Whitney Biennial in New York City about three or four years ago and became a huge fan. In the course of breaking the story I'm thinking, "OK, we're in Moscow. What gift might Yevgeni want to give to Carrie for finishing her book?" I'm thinking a jazz concert, but there's only one person we wanted to do it. It was just such a stroke of luck that he was in town at the right time and willing to do it and willing to perform live for our cameras. That was the most fun night of shooting the entire last season — being at the Los Angeles Theater and watching Kamasi Washington play two or three tunes live over and over again.

Do you plan to read reactions to the episode on Monday morning, or do you plan to retreat for a while?

The sad thing is that all of us in Los Angeles were going to get together and watch together. Now that's going to be a solitary experience for all of us. I will definitely be watching. And I know I'm not going to be able to resist checking out what people say on Monday. Fingers crossed that people are satisfied with the resolution. I don't know. It's the end, and I'm going to break my iron-clad rule about going on social media and seeing what people are saying. I'm really curious to see how people are going to respond.

What's next for you — development calls over Zoom?

If I get a paragraph done in a day, it's a good day. [Laughs.] Howard and I started a company. We made a deal at Sony, and we are in the process of developing a bunch of shows — none of which we are writing yet, but we're supervising. We're trying to figure out what our next project is. We've got a couple of contenders and we're just trying to figure out what the next show looks like. Obviously, it's so influenced by what we're all living through right now. What feels relevant? What is the next narrative to tell? Can you ignore or avoid what's happening to us right now? Especially on the heels of Homeland, where we had the privilege to comment contemporaneously on what's happening in the world. That's a tough act to follow.

This interview has been edited for length and clarity.