Chaos reigned on the streets of Kabul in August.

As part of its end of supporting “forever wars” and its withdrawal of troops from Afghanistan, in early July the U.S. military left Bagram Airfield in the dead of night — literally and symbolically abandoning the Afghan National Army that U.S. service members had spent nearly 20 years training and equipping.

By Aug. 15, the Afghan National Army had ­collapsed, and then-Afghan President Ashraf Ghani had fled.

In what appeared to the American public to be a matter of days, the Taliban had taken over once again.

At the capital’s Hamid Karzai International Airport, tens of thousands of desperate U.S. citizens, Afghans and U.S. allies were trying to flee through the last safe runway out.

It was a runway guarded by U.S. Marines.

Among the desperate were those who had helped the American military during the war, fearful that the Taliban would be out for revenge. That group included the parents and two brothers of Marine Cpl. Jason Essazay.

Essazay still had been in school in 2001 when the U.S. invaded Afghanistan and ousted the Taliban. But he had noticed an immediate improvement in his life, he said, and at his mother’s urging had started to learn English.

After high school he, along with two of his three brothers, worked as an interpreter for U.S. troops. The boys’ father had worked for the Afghan Air Force before becoming a contractor assisting the United States.

After his time as an interpreter, Essazay moved to Texas and enlisted in the Marine Corps Reserve in 2016 as an 0311 infantryman.

He has dreamed of returning to Afghanistan in a Marine uniform in the hopes of helping his home country, but that opportunity has not yet come true.

His decision to join the Corps, however, may have saved his family, which was stuck in Kabul Aug. 15.

“We were planning to leave Afghanistan before the Taliban came,” the Marine’s brother Omar Essazay told Marine Corps Times in a phone call. “We were waiting to get our visas but on the 15th of August the Taliban came.”

The Marine knew his family wouldn’t face a good fate if they tried to stay.

“We already had received so many death threats because of our affiliations with the U.S. military,” ­Essazay told Marine Corps Times in a phone ­interview.

And they were not alone.

Amid the mass panic, the U.S. military and local Afghans looked to the Marine Corps to provide the stability and safety needed to rescue thousands of people from the airport.

“I love my job,” Sgt. Nicole Gee had written in an Instagram post on Aug. 20 that showed her cradling an Afghan baby who had made it to safety within the Marine-held perimeter.

The Marines helped save nearly 130,000 people from the Taliban. But their efforts came at a cost.

Just six days after that Instagram post, Gee, along with 10 Marines, one Navy corpsman and a soldier, lost their lives as they tried to process just a few more refugees through the airport’s final open gate.

It’s a tragedy that Marines and Americans will have to sit with for a long time.

But, in those dire and frenzied weeks, wherever there was order and safety, there were Marines, steadfastly doing their duty on little notice and even less sleep — with the courage and competency that has become synonymous with the title “Marine.”

When the Marines of Combat Logistics Battalion 24, Gee’s unit, returned to Kuwait, they were greeted by a gunny who reminded them of the good they did.

“It is not many that would answer that f*cking call, but you f*cking did it and you did it with pride and professionalism,” Gunnery Sgt. Christopher Duncan McClain said, according to a video of his remarks posted to social media.

“You went over there and you helped people you never f*cking seen before, just because they are other humans and that’s what we f*cking do.”

‘I’m a Marine and here’s what I need’

With his family trapped in Kabul and the Taliban roaming the streets, Essazay reached out to one of his Marine Corps contacts.

Retired Marine Lt. Col. Russel Worth Parker had made a lot of connections in his 27-year Marine Corps career, which saw him go from intelligence, to infantry to special operations.

Leveraging his network, Parker contacted a Marine guarding one of the Kabul gates and then urgently sent a message to Essazay that his family had less than an hour to get there.

The family, taking nothing but the clothes on their backs and paperwork proving they were allies, ­navigated through Taliban checkpoints until they came face-to-face with Marines guarding the airport.

There, using a password given to them by Parker along with the assurance that they were related to a U.S. Marine, they were able to get to safety and eventually on a plane to Germany.

“Honestly it felt like after firefight,” Parker told Marine Corps Times in a phone interview.

“I was a force recon guy. I worked at night in Iraq, and you’d get into something overnight and you’d come back and watch the sun come up and have this kind of decompress time.”

“That’s what dawn felt like the morning after we got Jason’s family out.”

Knowing that he had the power to help people, Parker joined up with an organization informally known as “Team America” to help other interpreters and allies escape.

Though there may have been some semblance of calm inside the airport grounds at times, on the ­outside chaos and desperation still ruled.

But that chaos and desperation brought out the best of many of the Marines there.

On Aug. 19, a video showed Marines manning the outer fences pull a baby from the crowd and over the barbed wire.

The baby was taken to a medical treatment facility and then reunited with his or her father in ­safety, ­according to Maj. Jim Stenger, a Headquarters ­Marine Corps spokesman.

“This is a true example of the professionalism of the Marines on site, who are making quick decisions in a dynamic situation in support of evacuation ­operations,” he said in an Aug. 20 email.

While Pentagon-released images focused on the number of rescued babies and children and showed Marines aiding in relatively safe areas, a video released by a Marine with 1st Battalion, 8th Marines, showed what it was like outside the wire.

The video, released on the Instagram account of Cpl. Michael Markland, stitched together two-weeks’ worth of GoPro videos he shot.

The footage showed Marines attempting to hold back Afghans desperate to enter the airport. Sometimes they were working alongside what looked like Afghan allies who would shoot warning shots over the crowd to keep them from overrunning defenses.

The Marines would fire tear spray and other control munitions into the crowd to maintain order.

As the Aug. 30 withdrawal deadline for U.S. troops to leave the country approached, desperation ­increased and conditions worsened.

With the deadline nearing, Team America had 60 people outside one of the airport gates who were unable to make their way to safety.

Parker said he was able to call a Marine manning that gate.

“I just dialed this guy, and he actually picks up and you can hear the chaos in the background,” Parker said.

After telling the young Marine his background, Parker told him about the 60 people stuck just ­outside the gate.

“His response was pretty much, ‘Roger that sir, got it,’” Parker said.

“I felt so confident because another Marine 7,000 miles away on the end of that phone line said, ‘I got it; I’ll do it’ … I laid down and went to sleep for five hours,” Parker said.

Parker woke up the next morning with texts from the Marine asking for clarification — texts which caused the retired Marine to break down in tears because he “blew it.”

But Parker was wrong. Even without his clarification response, a group of Marines had gone out into the “maelstrom” and pulled those 60 people to safety.

“How amazing is that?” Parker said. “How many human beings get to experience that level of trust and that level of camaraderie that because I call this guy and said the magic words over the phone, ‘I am a ­Marine and here’s what I need,’ that guy injected himself into that maelstrom outside the gates and did what I asked him to do because I said it needed to get done.”

Babies when the war began

Though scores of people were reaching safety, the crowds outside the airport continued to grow.

It was under these conditions Marines with 2nd Battalion, 1st Marines, were standing post at the Abbey Gate on Aug. 26, when a suicide bomber approached a group processing refugees.

Other gates into the airport had shut down after ­intelligence received information that a possible suicide attack was imminent.

But the Abbey Gate stayed open to help the British evacuate its citizens and Afghans who provided them aid from the Baron Hotel, just a few hundred yards from the airport entrance.

As the Marines were waiting on the arrival of the British, they attempted to disperse the crowd to make it easier to spot a possible suicide bomber.

“We brought a truck with a loudspeaker down to try and disperse the crowd,” Maj. Ben Sutphen told CBS Mornings in the first official Marine eyewitness interview. “I was standing right by that truck when it happened.”

The ISIS offshoot organization Islamic State ­Khorasan, or ISIS-K, later claimed responsibility for the attack.

Sutphen said he was only 15 feet from the blast, but since he was on the opposite side of the truck he was only wounded in the attack.

After the suicide bombing, multiple gunmen opened fire on the Marines on the ground, according to Sutphen. But the Marines, still in shock from the explosion, were able to return accurate fire and ­quickly take out the enemy gunmen.

“I only got one of them out,” Cpl. Christian Sanchez, a Marine with 2nd Battalion, 1st Marines, Ghost Company, told Kara Hackney on Instagram.

“There were multiple,” he wrote. “After I took him down, my arm gave out because of the gunshot [wound]. I didn’t even feel it ‘till someone told me I was bleeding.”

Hackney has no connection to the Marines who deployed to Afghanistan, but after the Aug. 26 she dedicated her Instagram page to the wounded and killed, she told Marine Corps Times.

Sutphen credited Sanchez with saving several lives.

“He’s blown off his feet and still has his wits about him,” the Marine major told CBS. “Shot through the shoulder. Immediately recovers his weapon and puts the opposing gunmen down.”

“Without a doubt, many more Marine and civilian lives would have been lost,” if the Marines did not continue the fight, Sutphen added.

Though Sanchez’s arm was too injured for him to take out more than one ISIS fighter, he did not give up.

“Once my arm gave out, I helped drag a guy out, and someone told me to go to a medic, but I didn’t know why. … He started treating me, and that’s when I found out I was shot.”

Most of those U.S. troops killed had been mere ­babies when the war started and likely had no memory of the Sept. 11, 2001, attack that triggered it all.

“Nicole and I were babies when the war in ­Afghanistan began,” Sgt. Mallory Harrison said at Gee’s memorial service on Sept. 18.

Harrison was Gee’s best friend.

“We barely remember 9/11 when it happened and for nearly 20 years after, as we grew up, we watched as flag draped caskets, prayers went up around the country and thousands of families mourned the losses of their loved ones.”

The names of the U.S. troops killed in the suicide bombing are: Staff Sgt. Darin T. Hoover, 31, with 2nd Battalion, 1st Marine Regiment, out of Camp Pendleton, California; Sgt. Johanny Rosario Pichardo, 25, with 5th Marine Expeditionary Brigade, Naval Support Activity Bahrain; Sgt. Nicole Gee, 23, with Combat Logistics Battalion 24, 24th Marine Expeditionary Unit; Cpl. Hunter Lopez, 22, with 2/1; Cpl. Daegan W. Page, 23, with 2/1; Cpl. Humberto A. Sanchez, 22, with 2/1; Lance Cpl. David L. Espinoza, 20, with 2/1; Lance Cpl. Jared M. Schmitz, 20, with 2/1; Lance Cpl. Rylee J. McCollum, 20, with 2/1; Lance Cpl. Dylan R. Merola, 20, with 2/1; Lance Cpl. Kareem M. Nikoui, 20, with 2/1; Navy corpsman Maxton W. Soviak, 22, assigned to 1st Marine Regiment, 1st Marine Division, Camp Pendleton, California; and soldier Staff Sgt. Ryan C. Knauss, 23, assigned to 9th PSYOP Battalion, 8th PSYOP Group, Ft. Bragg, North Carolina.

McCollum left behind a pregnant wife on the verge of giving birth to their first-born daughter.

The 8-pound, 10-ounce, Levi Rylee Rose McCollum was born Sept. 13 at Naval Hospital Camp Pendleton, California, according to Facebook posts by the family.

“Welcome to the world my sweet baby,” Jiennah Crayton, the Marine’s wife and Levi’s mother, said in a Facebook post. “I love you with my whole heart.”

Fifteen service members wounded in the attack Aug. 26 were treated at Walter Reed National ­Military Medical Center in Bethesda, Maryland, after the incident.

As of Oct. 7, one Marine remained hospitalized, “in serious but stable condition.”

A total of 29 Purple Hearts were awarded to Marines and corpsman attached to Marine units who deployed to Afghanistan as of Sept. 10. Another 12 Purple Hearts were pending approval, Yvonne Carlock, a spokeswoman for Manpower and Reserve Affairs, told Marine Corps Times.

Twelve of the Purple Hearts already approved have been awarded to the Marines and corpsman who died Aug. 26. Carlock did not say how many awards for valor had been submitted in the wake of the deployment.

“Over the past two weeks we have had the opportunity to visit with some of your brothers and sisters recently wounded in Afghanistan,” said a Sept. 7 letter signed by Marine Corps Commandant Gen. David Berger and Sergeant Major of the Marine Corps Troy Black for the 20th anniversary of the Sept. 11, 2001, attacks.

“As anyone who knows Marines would expect, every one of them is eager to get back to their units as quickly as possible. All are positive, optimistic, and proud of their service,” the letter read.

Parker said that resiliency and the ability to get the job done no matter the conditions is a hallmark of the Corps that was on full display in August.

“In an incredibly dark time, in a chaotic situation … this was a shining moment for Marines.”