– Carrie Mathison has one more chance to save the world. “Homeland” kicks off its eighth and final season Sunday with the plucky CIA agent in position to help bring peace to Afghanistan.

It won’t be easy.

In the first new episode, the character is still reeling from serving more than 200 days in a Russian prison where the routine consisted of torture sessions and limited access to medication that keeps her bipolar disorder in check. Upon her release, certain American colleagues believe she can no longer be trusted, especially when her mentor, National Security Adviser Saul Berenson, springs her out of a German medical center early to help recharge stalled negotiations in Kabul. Mathison can’t wait to leap back into action and prove the skeptics wrong.

“She is so clear about her patriotism,” said Claire Danes, who has won two Emmys for playing the constantly rattled spy. “She can be challenged in every way, but if her patriotism is challenged, I think that is probably the most profound insult she can imagine.”

Mathison might have just been a female version of Jack Bauer in “24” if Showtime executives hadn’t initially implored the show’s producers to give the character more to struggle with than terrorists, double agents and crooked politicians.

“They asked us to push the boundaries, to make her, for lack of a better expression, more premium cable,” said co-creator Alex Gansa. “They wanted something that defined her in a way that was not just Chicken Little screaming that the sky was falling down every week.”

It was Gansa’s wife, Lauren White, who suggested making Mathison bipolar after reading “An Unquiet Mind: A Memoir of Moods and Madness” by Kay Jamison.

Danes, who won her first Emmy for playing the autistic Temple Grandin in an HBO movie, was concerned that the illness would be used simply as a gimmick, but she quickly discovered that the affliction put Mathison in a better position to understand how quickly matters can spiral out of control.

“She can’t take her sanity and her health for granted,” she said last month at the Television Critics Association press tour. “She knows that things can go boom. They can go wrong really, really fast. So, she is always vigilantly guarding against that, and I think it was easy for her to extrapolate and imagine the country in those terms. It’s about her vigilance and her protective impulse and her understanding that danger is real. I found it very moving.”

Also key to the drama’s success was the annual visit that writers and cast members would make to Washington, D.C., to pick up tips from actual members of the intelligence community and members of Congress.

Howard Gordon, who co-developed the series with Gansa, believes those advisers saw the show as a vehicle that showcased their dedication to America, even as they are accused of being embedded in some kind of deep state.

“The E ticket one gets when one is in a global storytelling mode is extraordinary,” said Mandy Patinkin, who has played Berenson since the show debuted in 2011. “I wouldn’t trade it for anything in the world. It’s been an education to say the very, very least.”

The show hasn’t been without its detractors.

The Lebanese government, Amnesty International and certain Muslim groups have all been critical of liberties the drama has taken. Laila Al-Arian, a journalist for the Al Jazeera Media Network, has called “Homeland” the most Islamophobic show on television.

“When you’re taking flak from the right for being soft on terror and you’re taking flak from the left for being Islamophobic, I think you’re in the right conversation. You’re doing the right thing,” Gansa said. “You’re causing people from both sides to attack you in a way for the same story line. The one theme on ‘Homeland’ is what the counterterrorism industry has done to us as a nation since 9/11, and that attitude can be mirrored in Carrie’s journey through this story. At the beginning, she was 100 percent gung-ho about keeping this country safe. And as the seasons progressed, she became disillusioned with how America was projecting its power overseas.”

Danes, for one, believes that a story could have kept going beyond these final 12 episodes.

“This could continue. I think of it like origami. It just gets reconfigured every season,” said Danes, who had two children with husband Hugh Dancy during the course of filming everywhere from North Carolina to Morocco. “I think it will be missed, but it’s so hard to make. I think it’s going to hit me that it’s over come April, when we would be going back to shoot the next season. When there’s that mark in the line and I really am confronted with the finality of it, I might be a little messy.”