The mob scene at the end of “Homeland’s” second-to-last episode of the season was hard to pull off with authenticity and difficult to shoot. And for the most part, they winged it. So says director Clark Johnson, who delivered his fifth “Homeland” seg to date with “Krieg Nicht Lieb.”

SPOILER ALERT: Stop reading if you haven’t seen the Dec. 14 episode of “Homeland.”

Johnson described the dueling protests that were pivotal to the plot as “Mets fans meet Yankees fans as they converge for a subway World Series.”

The goal was to depict a sense of chaos in the street as opposing factions meet, each chanting and carrying protest signs. In fact there was some anarchy behind the camera on location in Cape Town, South Africa, as Johnson and producers decided to let the extras loose and hope they could capture what they needed, mostly with hand-held cameras over three days.

“I just sort of shot it out of my a—,” Johnson told Variety. “It was not like we had a big shot-list situation. We just had to be there on the ground with all these people milling around. We had to think it through on the fly.”

Johnson drew some comfort from the fact that he’d worked with a number of the key crew members earlier in the year in lensing episodes of Starz’s “Black Sails,” which also shoots in Cape Town. He tipped his hat to “Homeland’s” art department for their ability to make Cape Town pass for Islamabad, Pakistan. “I didn’t think they could do it,” he said.

The plotline reminded Johnson of his youth growing up in the Civil Rights era when he was often warned that J. Edgar Hoover’s minions would plant agitators in the midst of large-scale demonstrations to incite violence. In “Homeland’s” case, supporters of the enigmatic terrorist Haqqani were battling earnest medical students who became aware that Haqqani murdered one of their own, his own nephew Aayan, after rogue CIA agent Peter Quinn deliberately leaked drone footage of the shooting to stir up the students.

“You had two incredible forces of energy colliding there, and Claire trying to make sense of it all,” Johnson said.

Like other “Homeland” helmers, Johnson marvels at the range Claire Danes’ Carrie Mathison has to play in any given episode. “It strikes me how much they ask of that woman,” he said, admiringly. “She’s an amazing force.”

He noted that in the nine-day shoot for “Krieg Nicht Lieb,” plenty of scenes were lensed out of order, meaning that Danes had to seesaw from anger to fear to the heartache of learning of her father’s death and feeling maternal pangs of missing her daughter. The same was true for Rupert Friend’s Quinn. Johnson knows whereof he speaks as he has spent plenty of time in front of the camera too on such series as HBO’s “The Wire” and NBC’s “Homicide.”

“That’s an emotional roller coaster to be up and down like that and do all that we need to do to make our day (of production),” Johnson said.

Amy Hargreaves, who plays Carrie’s sister, Maggie, came to Cape Town to shoot her scenes with Carrie, even though the two were conversing via videoconference on a laptop computer. Having the two actors working on the scene at the same time allowed both to deliver better performances, Johnson said. Nonetheless it was quite a trek for Hargreaves for a small amount of work.

Shooting that scene also gave the “Homeland” team an opportunity to pay tribute to the late actor James Rebhorn, who played Carrie and Maggie’s father, Frank Mathison, in the first three seasons. Rebhorn died in March. Coincidentally, Johnson had been involved in the casting of Rebhorn back in “Homeland’s” first season. The actors and crew members took some pictures and said a few words about the veteran character thesp. “It was a good moment of closure for the company,” Johnson said.

The surprise of the episode for Johnson was how easily German actress Nina Hoss fell into the role of Quinn’s ex-lover Astrid, the flinty German embassy staffer. Astrid provides a key assist in Quinn’s quest to take out Haqqani — and she gives Carrie a vital insight into her mysterious co-worker’s character.

Johnson had been impressed with Hoss’ work in the 2014 Philip Seymour Hoffman movie “A Most Wanted Man” and was happy to learn she would be working on his latest “Homeland” seg.

“It was tough to get her, and she gave so much to that role,” Johnson said. “The character was on the page, but as an actor you can bring so many more colors to it. She was just so nuanced and worthy of being a collaborator with Quinn and in (sparring) with Carrie.”

After a pause, he added: “I mean, you’ve got to bring your A-game to do ‘Homeland.’ ”

The starting lineup for next week’s finale: writer Meredith Stiehm and director Lesli Linka Glatter.