The U.S. has been fighting the war in Afghanistan for more than 12 years, and few Americans have come to know the country in the way Dilip Joseph has. Joseph, who has been there 10 times in the past four and a half years, is a doctor who works with a nonprofit group and trains health care workers.

The job has taken him to clinics and community centers deep in the war zone. "The motto is to 'work yourself out of a job,' " he says. "Equip others, train others in areas where you've gotten training."

Joseph tells All Things Considered's Arun Rath that he has always been aware of security concerns. But his last trip — his 10th — was different. On Dec. 5, 2012, he came face to face with the Taliban.

"On this particular occasion, we were travelling from Kabul to one of our most rural community centers," he says. Joseph does not speak Pashto, the local language, so he travelled with two Afghan colleagues. After finishing their work that day, they went to a local police chief's house for lunch.

"There was some conversation going on about security measures in the area, and I didn't think much of it," he says. "I think, in retrospect, I was thinking maybe [the police chief] was picking up certain things that I certainly wasn't aware of."

So Joseph and his two colleagues began driving back to Kabul. As they came down a winding mountain road, a man with a gun suddenly emerged.

"I didn't see him initially, but the driver did, and he put the brakes on very quickly," Joseph says. "As soon as this guy fired a warning shot, we saw more people from the front and the back sort of cover us. I think there were about four of them with guns that covered us right away.

"Being an ethnic Indian — I look not very different from [the insurgents]. So they certainly didn't know who the foreigner was, so I don't think they picked up on the fact until we were put back into our vehicle and taken to a very remote area," he adds. "At that point, they looked a bit more closely through my belongings and my backpack, and unfortunately I had my American passport in my bag. And they figured out I was an American."

That, Joseph says, changed things dramatically.

"At that point, they knew right away — just from looking at the passport — that they could raise the stakes, so to speak," he says.

"We got to this remote valley. Our hands were tied, and we started hiking, which was very difficult," Joseph says. "That hiking took about nine, nine and a half hours. So when we did sit down for the very first time, I did try to connect with them, saying, you know, 'I'm originally from your part of the world, and I come here to treat your brothers and sisters and your mothers and fathers.' I wanted that to be a two-way conversation, but it was very much a monologue."

At this point, he says, the idea that his life was in danger was at the front of his mind. So he went through an "interesting and very relieving exercise" of realizing that he could be killed.

"I thought through all the different ways I've already had a very blessed life, and counted all the different ways that I've been able to live a good life so far," Joseph says. "So I did, certainly, go through that mental exercise of realizing, 'Yeah, this could be a dire situation for me.' ... I didn't want to be pissed off right before getting killed."

As the sun went down, Joseph says, the group hiked by moonlight to a remote shack. There, the three kidnappers made their demands: they wanted $300,000 and threatened to take the group to Pakistan if they didn't receive the money. They also threatened to kill the hostages if the captors' commands weren't obeyed.

He was allowed to call his office in Kabul to report the kidnapping and to relay the demands. But as the second day wore on, the group lost cell phone service. And through the translator, Joseph's three captors began to talk with him.

"They had a lot of questions about what my life was like, what my family was like, and why I do what I do," he says. "And, you know, going through that — opening up my own life — really enabled this one young man, who was 19 years old, to open up about his own life.

"He was sort of almost comparing his life to mine. And in that conversation, I figured out that he was 19 year old, and I stopped him right there and said, 'You know, I'm 39, and I'm old enough to be your father.' And then he opened up about his father being in prison for the past 14 years. So essentially he had only seen his father for five years, and those five years, all he had seen his father do were insurgency activities. And so he made this conclusion of, 'Well, your parents taught you something else than what my parents taught me, and that's why you do what you do. And the reason why I do things that I do is because I haven't been taught anything else.' "

Joseph says negotiations for his release eventually broke down, and by the fourth day of captivity, the kidnappers decided to split up the group.

"When my colleagues left, I pretty much figured that this was the last time we were going to see each other," he says. "So I hugged them goodbye and teared up as I was doing that. And three of these five men came up and wiped my tears. Of course, a couple of them didn't even bother connecting with me. If anything, they would make rude gestures about how they were going to kill me and about how they were happy about this whole captivity."

Then came the fourth night. At that point, Joseph was being held in a small, pitch-black room. He heard dogs barking outside and the sheep making noise. He also heard gunfire. Then a man burst through his door: It was a Navy SEAL, a rescue operation. But Taliban gunfire hit that man, who was a member of the elite SEAL Team Six.

Other members of the SEAL team called out to Joseph, and he called back.

"As soon as the SEALs recognized where my voice was coming from, one of them just came and laid on top of me. And others must have taken out most of these guys, except for the 19-year-old," Joseph says. "So as I walked out, I saw this 19-year-old just lock eyes with me. And then when I was brought back into the room, because the helicopter was going to take a few more minutes to come, I did see that he was also killed."

In a few short moments, it was all over. The Navy SEAL who had been shot, Petty Officer 1st Class Nicolas Checque, was dead. He was 28 years old. A helicopter arrived and brought Joseph to a military base. His Afghan colleagues also made it to safety.

A few days after the rescue, Joseph returned home to his family in Colorado. In a statement, they said: "We could not be more grateful for that soldier's heroism and for the bravery of all involved in the mission to bring Dilip home."

Since then, Joseph says he has had time to sort out the complicated emotions of his captivity:

"What [this experience] made me realize is that even the Taliban can be reached. Because at the end of the day, they realize that this is a dead end, what they're doing. And they're also having the simple desires that you and I have — for a better future, better education for their kids. So this experience does give me — as ironic as this sounds — more hope than I had even before."