The CIA believed he was a “golden source,” a top-secret informant who had penetrated al-Qaeda and brought the agency within striking distance of the terrorist group’s senior leadership. But Humam al-Balawi, a Jordanian pediatrician turned spy, was not what he seemed.

In late 2009, several months before the CIA learned of Osama bin Laden’s Pakistani hideout, Balawi appeared to offer the agency the best chance in a decade to find and kill al-Qaeda’s then-No. 2 leader, Ayman al-Zawahiri. But his stunning reports from inside the terrorists’ camp were part of an elaborate trap that culminated in the deaths of nine intelligence operatives, including seven Americans, at a CIA base in eastern Afghanistan. The strike was the deadliest blow against the agency in a quarter-century.

In this excerpt from his forthcoming book, “The Triple Agent,” Washington Post reporter Joby Warrick traces Balawi’s treacherous final days as he first avoids, and then commits to, the sacrifice of his own life to kill his enemies.

The Pashtun tribesman known as al-Qaeda’s tailor lived in a house near the village of Datta Khel in the Pakistani tribal region of North Waziristan, where he made a living making suicide vests. One morning in mid-December, he sat at his antique sewing machine to fill yet another order, this one very different from the vests he usually made.

The man was celebrated for his ingeniously simple designs that were both reliable and cheap. He started with a sturdy cotton vest, often surplus military gear from the local bazaar, and attached thick straps so it could be secured snugly against the torso. He added fabric pouches and stuffed them with packets of white acetone peroxide powder, an explosive that can be cooked up at home using common ingredients. Next came the shrapnel layer, which consisted of hundreds of nails or other bits of metal glued to sheets of thick, adhesive-backed paper or cloth. Finally, he inserted blasting caps in the powder and attached them to wires that ran to a small nine-volt battery and a cheap detonator switch. The latter item he sewed into a separate pouch that closed with a zipper. That, he explained, was to prevent excitable young martyrs-to-be from blowing themselves up too quickly. An extra second or two of fumbling with the zipper would remind the bomber to move in closer to his target to ensure the maximum possible carnage.

On this day a group of young Pakistani recruits, some of them tapped as future suicide bombers, gathered to admire the vestmaker as he worked. One of them took photos with his cellphone as the man reached into his explosives chest and pulled out a surprise: not the usual bags of powder, but doughy sticks of a far more powerful military explosive called C4. He kneaded the sticks to flatten them and began to pack them into a row of 13 fabric pouches he had sewn onto the outside of the vest. Next he dipped a paintbrush into a bucket of industrial adhesive and slathered the white goo over a large square of sturdy cotton. The man then patiently studded the sheet with metal bits, piece by piece and row by row, alternating marble-size steel ball bearings with nails and scrap and, finally, some children’s jacks.

Among the spectators, there had been lively discussions about the man who was likely to wear the special vest. Most speculation centered on the young Jordanian physician whom the recruits called Abu Leila, using the Arab practice of referring to men by the name of their oldest child and the word abu, or “father of.” But Leila’s father wasn’t nearly so certain. Before he left for Pakistan, Humam al-Balawi imagined himself a mujaheddin, a holy warrior, fighting and maybe even dying in a righteous struggle against the enemies of God. What he hadn’t pictured for himself was a suicide vest.

The one in the tailor’s shop in Datta Khel was coming together, row after metal-studded row, but there was still time. In the coming days Balawi tried his best to make sure that the vest ended up belonging to someone else. Anyone but him.

***

The forces that would compel Balawi’s arrival at the CIA base at Khost, in eastern Afghanistan, had been gathering momentum for months. The crude outlines of Balawi’s course had been set 10 months earlier in Amman, Jordan, when he volunteered to work as a spy, and weeks later, when intelligence officers dispatched him to Pakistan despite his utter lack of experience. The path became clearer when a CIA missile killed Balawi’s Pakistani host, Taliban commander Baitullah Mehsud, heightening the militants’ thirst for revenge. On the U.S. side, the pace quickened when Balawi sent the CIA photographic proof that he had cracked al-Qaeda’s inner circle. From its highest levels, the agency was determined to confront Balawi. The only question was where.

Only one location made sense for the meeting, wrote Sharif Ali bin Zeid, a Jordanian intelligence officer who was Balawi’s handler, in an e-mail to his agent. It was the American base at Khost, just across the Afghan border. Balawi could travel there quickly and return to Pakistan before anyone missed him. Khost offered complete security and protection from accidental discovery by Taliban spies.

But Balawi seemed uninterested in coming to the CIA base. As he well knew, going to Khost would be akin to breaking into a prison. There would no chance for an ambush or kidnapping, and no al-Qaeda fighters waiting for the command to attack. Even if he could somehow smuggle a gun onto the base, he would almost certainly be disarmed or killed before he could squeeze off a single round.

Not possible, he wrote back.

A visit to the CIA base did offer one way to strike a blow against Jordanian intelligence and possibly the Americans as well. But this option would be a solo mission and a one-way trip. To succeed, he would have to somehow make it past layer after layer of security, starting with multiple rings of Afghan and American guards, followed by pat-downs, bomb-sniffing dogs and metal detectors. His likeliest victims might well be the low-paid Pashtun wretches who stood sentry outside the base.

Balawi’s feelings about a possible suicide mission can be deduced from the urgency of his efforts to avoid Khost. Through early December 2009, and continuing for weeks after bin Zeid arrived at the American base, he begged the Jordanian intelligence officer to come to him instead, in the town of Miranshah on the Pakistani frontier. Next he offered Ghulam Khan, a checkpoint on the Afghanistan-Pakistan border on the highway that runs from Miranshah to Khost. The answer from bin Zeid was the same: Come to Khost.

His options dwindling as December neared its end, Balawi sat down one evening to write, as though he could somehow exorcise his doubts by putting them on paper.

“I have often wished to know what is going on in the head of a martyr before the martyrdom-seeking operation,” he wrote. “It is now my turn today to fulfill the wishes of others.”

He began to list his private fears, pausing to admit deep misgivings about the value of suicide attacks. The problem, he acknowledged, is that one could “only do it once in your life,” and there was a real chance that he would fail and squander his life for nothing. A harder question was whether he could go through with it. How would he feel in those final seconds, with only a slight twitch of his finger separating him from annihilation?

“Do you not fear to be cowardly at the last moment,” he asked himself, “and be unable to press the button?”

On Dec. 28, Balawi e-mailed a brief note to his countryman bin Zeid. You win, he wrote. I’ll meet your driver in Miranshah.

Afterward Balawi and two al-Qaeda associates drove to a field to record some video footage of the Jordanian firing a few rounds from an AK-47, the gun jerking upward as bullets kicked up dust spouts in the distance. Then he went to his room to put on the suicide vest. He tightened straps that bore the weight of 30 pounds of explosive and metal. He put on his khameez shirt and gray patou, the shawl-like blanket that doubles as a cloak and mobile prayer mat, and walked back outside, where his friend with the video camera was waiting beside a white hatchback.

Balawi sat in the driver’s seat as the camera rolled. He had decided that his martyr’s message should be in English, to ensure the widest audience if the video made its way to the Internet, and he had chosen lines intended to project a kind of cinematic, bad-guy toughness, as though he were a Hollywood mobster delivering an ultimatum.

“We will get you, CIA team. Insha’Allah — God willing — we will bring you down,” he said. “Don’t think that just by pressing a button and killing mujaheddin, you are safe,” a reference to missile strikes from CIA drones. “Insha’Allah, we’ll come to you in an unexpected way.”

Balawi raised his left hand to reveal what appeared to be a wristwatch beneath his sleeve. “Look, this is for you: It’s not a watch, it’s a detonator,” he said.

But the tough-guy routine was falling short. Balawi seemed agitated and bitter, and he turned his head from the camera whenever he finished a thought. His eyes were red as he spit out his last words.

“This is my goal: to kill you, and to kill your Jordanian partner, and Insha’Allah, I will go to al-Firdaws — paradise,” he said. “And you will be sent to hell.”

With the final phrase his voice cracked, as though he were straining to fight back tears. Balawi looked away, and the image went dark.

***

Balawi scanned the line of cars and taxis, holding the crutch he used in the aftermath of a leg injury, looking for his ride. It was mid-afternoon on Dec. 30 when he finally arrived at Ghulam Khan, the only border crossing between Pakistan’s North Waziristan province and Afghanistan. The checkpoint, a cluster of mud-brick buildings on the Pakistani side, was manned by a handful of guards with rifles and one antique machine gun with its barrel pointed toward Afghanistan.

Balawi found his contact, a tall, solidly built Afghan gesturing to him from the cluster of taxis. Greeting Balawi in Pashtun-accented English, the Afghan officer, called Arghawan, opened the door of a small sedan to let Balawi inside. The driver mumbled a few words into his cellphone, and the two men began an hour-long trek down the mountains and into a dry plateau on the Afghan side of the border.

Sometime after 4:30 p.m., a large airfield appeared in the distance.Khost. Balawi used the driver’s cellphone to dial a number, and in a moment a voice in familiar Arabic came on the line.

“Salam alekum,” said bin Zeid. Peace be with you.

Balawi apologized for the delay and repeated his concerns about being poked and prodded by Afghan guards who might well be spies. “You’ll treat me like a friend, right?” he asked.

Bin Zeid was reassuring.

The car slowed at the approach to the main gate of the Khost base and passed through a canyon of high walls that narrowed at one end, channeling vehicles into the kill zone of a 50-caliber machine gun. Balawi sat low in his seat, the weight of the heavy vest pressing against his gut, but as bin Zeid had promised, there was no search. Arghawan turned left into the main entrance, and the car barely slowed as it zigzagged around a final series of barriers and into the open expanse of the Khost airfield.

The car turned left again to travel along the edge of the runway, past tanker trucks and dun-colored armored troop carriers.

Balawi, in his writings, had imagined the djinn — devils — and their whispered doubts.

“Are you going to perform jihad and get yourself killed, and let your wife remarry and your children become orphans?

“To whom are you leaving your pretty wife? Who will be dutiful to your frail mother?

“How can you abandon your wonderful work?”

There was an opening in a wall, and Arghawan steered the car through a second open checkpoint and then turned left through a third. Balawi was now inside a fortified compound with walls of stacked barriers 10 feet high and topped with razor wire. On the side of the compound opposite the gate were five newly constructed buildings with metal roofs and a few smaller ones. The next-to-last building in the row had a wide awning. Balawi could see a large cluster of people scattered in front of it, a welcome party that included CIA officers and security contractors.

***

Arghawan stopped the vehicle in the middle of a gravel lot in front of the building, parallel to the awning but several car lengths away from it. From his spot in the back seat behind the driver, Balawi could see bin Zeid, wearing a camouflage hat and standing next to a larger man in jeans and a baseball cap.

Balawi was staring blankly at the group when the car door opened and he was suddenly face to face with a bear of a man with a close-cropped beard and piercing blue eyes. One gloved hand reached for Balawi, and the other clutched an assault rifle, its barrel pointed down. Balawi froze. Then, slowly, he began backing away, pushing himself along the seat’s edge away from the figure with the gun.

Balawi squeezed the door handle on the opposite side and climbed out of the car, swinging his injured leg onto the gravel lot, and then the good one. Painfully he pulled himself erect, leaning on his metal crutch for support. Bin Zeid called out to him, but Balawi would not look up.

He began walking in a slow-motion hobble as his right hand felt for the detonator.

Just at the brink, the djinn would pose the most awful questions, he had written.

“Who will take care of your little child? And your elderly father?”

Men were shouting at him now, agitated, guns drawn.

“It is said in the Hadith that he who says, ‘There is no God but God alone and praise be to Him,’ he is protected by God from Satan on that day,” Balawi had written. “On the day of the martyrdom-seeking operation, the enemy of God will not reach you.”

Now Balawi mouthed the words softly in Arabic. “La ilaha illa Allah!” There is no god but God.

Men were shouting loudly, yelling about his hand, but still Balawi walked. He could hear his own voice growing more distinct.

“La ilaha illa Allah!”

Balawi’s path was now blocked. He looked up to see that he was surrounded on two sides by men with guns drawn. The bearded man who had opened the car door had circled around him and was shouting at him from his left, and two other heavily armed officers stood directly in front of Balawi, trapping him against the car with no way forward or back. One of the men, blond and younger than the others, was crouching as though preparing to lunge.

Balawi turned slightly, finger locked on the detonator, and looked across the top of the car. The smiles had vanished, and bin Zeid was starting to move toward him. As he did, the tall man beside him grabbed his shoulder to pull him back.

Balawi closed his eyes. His finger made the slightest twitch.