In this stormy political season, leave it to “Homeland” to adroitly land in the eye of Hurricane Trump.

Producers of the Showtime drama series, which returns on Sunday, chose New York as the setting for its sixth season more than a year ago. They’ve been working for months on a storyline examining the post-9/11 fallout for the civil rights of Muslims in the U.S. and upheaval in the national security community caused by a transfer of power in Washington.

But as much as the “Homeland” team as proven their ability during the past few years to predict headlines, showrunner and exec producer Alex Gansa admitted that the writing staff had to work through what felt like an existential crisis on Nov. 9.

“After Election Day we all came into the story room and wondered if ‘Homeland’ had just become counterfactual to the point of irrelevance,” Gansa told Variety.

The new season takes place during that nebulous transition period between a presidential election and the inauguration — 72 days of adjustment and upheaval in Washington under any circumstances. “Homeland” decided to elect a female president, played by Elizabeth Marvel, who is an avowed maverick with a deep-seated suspicion of the inner-workings of the intelligence community in which Carrie Mathison and Saul Berenson ply their trade.

But it wasn’t the gender of “Homeland’s” fictional president-elect that made the writers nervous after Donald Trump’s upset victory over Hillary Clinton.

“The uncertainty of a Donald Trump presidency felt outside the bounds of imagination,” Gansa said. “We were initially concerned that what was happening in the real world was so much more uncertain than what we were dramatizing on television.”

Just in the past few days, the real president-elect has validated many of the choices the “Homeland” team has made for their president-elect, Elizabeth Keane. Trump’s recent scrapes with the CIA and other aspects of the national security industrial-complex are mirrored in “Homeland” scripts this season. The storyline was influenced, as always, by the “Homeland” team’s annual research field trip to Washington, D.C. Gansa was struck by what he learned about how the post-election transition period can change the viewpoints of a president-elect, despite their campaign rhetoric, once they begin to receive high-level briefings from intelligence officials. President Obama, for one, modulated his criticism of drone warfare after receiving his first briefings while still in his transition headquarters in Chicago, Gansa learned.

At a fraught moment for political discourse, “Homeland’s” story choices this season are sure to provoke equal amounts of debate and catcalls. Disillusioned by the ineffectiveness of waging war against international terrorism, Claire Danes’ Carrie has done a 180-degree career turn and set herself up in Brooklyn as an advocate for the legal rights of American Muslims. She becomes involved in a case that very deliberately pushes the First Amendment boundaries of what many Americans would consider acceptable speech.

Sekou Bah, played by J. Mallory McCree, is a young man who immigrated from Africa as a kid and is angry about the fact that his father was deported just after 9/11. He takes to the internet to deliver screeds against the federal government and praise Islamic militants.

“We went to great lengths to make Sekou a guy whose behavior would be abhorrent to a large portion of America, but the question is: is it illegal?” Gansa said. “These are all questions that federal judges and juries have to weigh all of the time.”

Meanwhile, Mandy Patinkin’s CIA lifer Saul is facing the challenge of working for a president who comes into the office questioning the value of continuing the scorched-earth campaigns to root out domestic terror cells. And Rupert Friend’s ruthless CIA operative Peter Quinn has gone through quite a personal transformation as he recovers from the nearly fatal exposure to chemical weapons that he suffered at the end of Season 5.

The big twists in the Peter Quinn story have been “energizing” for writers, Gansa said.

“Here’s an example of character that we came to know one way, and this season we find him utterly changed,” Gansa said. “It’s been an interesting experience to write around this new conception of Peter Quinn.”

The beating heart of “Homeland,” of course, remains Carrie Mathison. As depicted in the first two episodes of the season, she’s changed in ways that appear to be mostly positive. Living in Brooklyn with her daughter, Frannie, and a clearly defined sense of purpose seems to suit her. In her new life as an advocate, she’s on a mission to help one person at a time rather than shouldering the 24/7 burden of trying to spare the world more terror attacks.

“Every season we have to locate Carrie emotionally,” Gansa said. It felt appropriate that Carrie would be a little more together this time out. “She’s managing her illness better. She’s not drinking. She’s coping in a way that she hasn’t been able to in the past,” he said.

Behind the scenes, “Homeland’s” core cast members are coping quite nicely with the assignment to shoot in New York, after globe-trotting during the past two seasons to South Africa, Morocco and Berlin. “There’s nothing like working from home,” Gansa said.

When the decision was made to lense in New York, there was no way of knowing that the presidential transition events depicted in the scripts would be unfolding in Trump Tower on Fifth Avenue. The turn of events has added some extra sizzle to “Homeland’s” location work in Times Square and other iconic settings.

But in other ways, the team is happy to be just another small piece of the city that never sleeps.

“New York for the most part has been profoundly indifferent to our presence, in a way that we didn’t see in Berlin or Cape Town,” Gansa said.