In 1959, the U.S. Navy sent Stockdale to Stanford University where he received a masters degree in international relations and comparative Marxist thought. Stockdale preferred the life of a fighter pilot over academia, but later credited Stoic philosophy with helping him cope as a prisoner of war.

On 2 August 1964, while on a DESOTO patrol in the Tonkin Gulf, the destroyer USS Maddox (DD-731) engaged 3 North Vietnamese Navy P-4 torpedo boats from the 135th Torpedo Squadron.[3] After fighting a running gun and torpedo battle, in which the Maddox fired over 280 5-inch shells, and the torpedo boats expended their 6 torpedoes (all misses) and hundreds of rounds of 14.5mm machinegun fire; the combatants broke contact. As the torpedo boats turned for their North Vietnamese coastline, four F-8 Crusader fighter aircraft from USS Ticonderoga (CV-14) arrived, and immediately attacked the retreating torpedo boats.[4]

Two nights later, on August 4, 1964, Stockdale was overhead during the second reported attack in the Tonkin Gulf. However, unlike the first event, which was an actual sea battle, no Vietnamese forces were believed to have been involved in the second engagement. In the early 1990s, he recounted: "[I] had the best seat in the house to watch that event, and our destroyers were just shooting at phantom targets—there were no PT boats there.... There was nothing there but black water and American fire power." Stockdale said his superiors ordered him to keep quiet about the details of that night.

The next morning on August 5, 1964, President Johnson ordered bombing raids on North Vietnamese military targets which he announced were retaliation for the alleged incident of August 4. When Stockdale was awoken in the early morning and was told he was to lead these attacks he responded, "Retaliation for what?" Later, while a prisoner of war, he was concerned that he would be forced to reveal this secret about the Vietnam War.

Flying from USS Oriskany on a mission over North Vietnam on September 9, 1965, Stockdale ejected from his Douglas A-4E Skyhawk, which had been struck by enemy fire and completely disabled. He parachuted into a small village, where he was severely beaten and taken prisoner.

Stockdale was held as a prisoner of war in the Hoa Lo prison for the next seven and a half years. As the senior Naval officer, he was one of the primary organizers of prisoner resistance. Tortured routinely and denied medical attention for the severely damaged leg he suffered during capture, Stockdale created and enforced a code of conduct for all prisoners which governed torture, secret communications, and behavior. In the summer of 1969, he was locked in leg irons in a bath stall and routinely tortured and beaten. When told by his captors that he was to be paraded in public, Stockdale slit his scalp with a razor to purposely disfigure himself so that his captors could not use him as propaganda. When they covered his head with a hat, he beat himself with a stool until his face was swollen beyond recognition. When Stockdale was discovered with information that could implicate his friends' "black activities", he slit his wrists so they could not torture him into confession.

Early in Stockdale's captivity, his wife, Sybil Stockdale, organized The League of American Families of POWs and MIAs, with other wives of servicemen who were in similar circumstances. By 1968, she and her organization, which called for the President and the U.S. Congress to publicly acknowledge the mistreatment of the POWs (something that had never been done despite evidence of gross mistreatment), gained the attention of the American press. Sybil Stockdale personally made these demands known at the Paris Peace Talks.

President Gerald Ford presents the Medal of Honor to Stockdale at the White House on March 4, 1976.

Stockdale was one of about eleven prisoners known as the "Alcatraz Gang": George Thomas Coker, George McKnight, Jeremiah Denton, Harry Jenkins, Sam Johnson, James Mulligan, Howard Rutledge, Robert Shumaker, Ronald Storz and Nels Tanner. These individuals had been leaders of resistance activities while in captivity and thus were separated from other captives and placed in solitary confinement. "Alcatraz" was a special facility in a courtyard behind the North Vietnamese Ministry of National Defense, located about one mile away from Hoa Lo Prison. In Alcatraz, each of the prisoners was kept in an individual cell measuring 3 feet by 9 feet with a light bulb kept on around the clock, and they were locked in leg irons each night.[6][7][8][9][10]

In a business book by James C. Collins called Good to Great, Collins writes about a conversation he had with Stockdale regarding his coping strategy during his period in the Vietnamese POW camp.[11]

I never lost faith in the end of the story, I never doubted not only that I would get out, but also that I would prevail in the end and turn the experience into the defining event of my life, which, in retrospect, I would not trade.[12]

When Collins asked who didn't make it out of Vietnam, Stockdale replied:

Oh, that's easy, the optimists. Oh, they were the ones who said, 'We're going to be out by Christmas.' And Christmas would come, and Christmas would go. Then they'd say, 'We're going to be out by Easter.' And Easter would come, and Easter would go. And then Thanksgiving, and then it would be Christmas again. And they died of a broken heart.[12]

Stockdale then added:

This is a very important lesson. You must never confuse faith that you will prevail in the end—which you can never afford to lose—with the discipline to confront the most brutal facts of your current reality, whatever they might be.[12]

Witnessing this philosophy of duality, Collins went on to describe it as the Stockdale Paradox.

Stockdale was released as a prisoner of war on February 12, 1973. His shoulders had been wrenched from their sockets, his leg shattered by angry villagers and a torturer, and his back broken.

He received the Medal of Honor in 1976. Stockdale filed charges against two other officers (Marine Corps Lieutenant Colonel Edison W. Miller and Navy Captain Walter E. "Gene" Wilber) who, he felt, had given aid and comfort to the enemy. However, the Navy Department under the leadership of then-Secretary of the Navy John Warner took no action and retired these men "in the best interests of the Navy."[13][14]

Debilitated by his captivity and mistreatment, Stockdale could not stand upright and could barely walk upon his return to the United States, which prevented his return to active flying status. In deference to his previous service, the Navy kept him on active duty, steadily promoting him over the next few years before he retired as a vice admiral. He completed his career by serving as President of the Naval War College from October 13, 1977, until August 22, 1979.

After his retirement in 1979, he became the President of The Citadel, The Military College of South Carolina. His tenure there was short and stormy as he found himself at odds with the college's board as well as most of its administration, by proposing changes to the college's military system and other facets of the college, including the curbing of student hazing. He left The Citadel to become a fellow of the Hoover Institution at Stanford University in 1981. During his twelve year tenure at the Hoover Institute, Admiral Stockdale wrote and lectured extensively. His primary focus was ancient stoicism and the Roman slave-turned-author Epictetus, whose lessons captured in The Enchiridion (The Handbook) Stockdale credited with providing him strength during his ordeals as a prisoner in Hanoi. Between 1981 and 1988 Admiral Stockdale also served as chair of the White House Fellows under the Reagan administration.

In 1984 Admiral Stockdale and his wife Sybil co-authored In Love and War: the Story of a Family's Ordeal and Sacrifice During the Vietnam War which was published by Harper and Row. It recounts Stockdale's experiences while in Vietnam and in alternating chapters also tells the story of Mrs. Stockdale's early involvement in the League of American Families of POW's/MIA's which she helped to found and served as its first chairperson. Their story was later made into an NBC television movie under the name In Love and War starring James Woods and Jane Alexander.

Stockdale came to know businessman and presidential candidate H. Ross Perot through his wife's work in establishing an organization to represent the families of Vietnam POWs. On March 30, 1992, Perot announced that he had asked Stockdale to be his provisional Vice Presidential nominee on Ross Perot's 1992 independent ticket.[16] Perot intended to replace Stockdale with another candidate, but did not do so before he dropped out of the race in July 1992.[17]

Perot eventually re-entered the race in the fall of 1992, with Stockdale still in place as the vice-presidential nominee. Stockdale was not informed that he would be participating in the October 13 vice-presidential debate held in Atlanta, Georgia, until a week before the event. He had no formal preparation for the debate, unlike his opponents Al Gore and Dan Quayle, and did not discuss any political issues with Perot beforehand.[17]

Stockdale notably opened the debate by saying, "Who am I? Why am I here?", when responding to a request for an opening statement from debate moderator, Hal Bruno, the political director of ABC News.[18] Bruno had asked Stockdale, "Admiral Stockdale, your opening statement, please, sir?", leading to the now famous response.[19] Initially, the rhetorical questions drew applause from the audience, seeming to be a good-natured acknowledgment of his relatively unknown status and lack of traditional qualifications.

However, his unfocused style for the rest of the debate (including asking the moderator to repeat one question because he didn't have his hearing aid turned on) made him appear confused and almost disoriented. An unflattering recreation of the moment on Saturday Night Live later that week, with Phil Hartman as Stockdale, cemented a public perception of Stockdale as slow-witted. He was also often parodied for his repeated use of the term "gridlock" to describe slow governmental policy.

As his introduction to the large segment of American voters who had not previously heard of him, the debate was disastrous for Stockdale. He was portrayed in the media as elderly and confused, and his reputation never recovered. In a 1999 interview with Jim Lehrer, Stockdale explained that the statements were intended as an introduction of himself and his personal history to the television audience:[17]

It was terribly frustrating because I remember I started with, "Who am I? Why am I here?" and I never got back to that because there was never an opportunity for me to explain my life to people. It was so different from Quayle and Gore. The four years in solitary confinement in Vietnam, seven-and-a-half years in prisons, drop the first bomb that started the ... American bombing raid in the North Vietnam. We blew the oil storage tanks of them off the map. And I never—I couldn't approach—I don't say it just to brag, but, I mean, my sensitivities are completely different.

Perot and Stockdale received 19 percent of the vote in the 1992 presidential election, one of the best showings by an independent ticket in U.S. electoral history, although they did not carry any states.

The U.S. Navy has named a number of structures after Stockdale, including the Arleigh Burke–class guided missile destroyer USS Stockdale (DDG-106), christened on May 10, 2008.[21] At the Naval Air Station North Island in Coronado, California, the main gate (inaugurated on August 30, 2007) and the headquarters building for the Pacific Fleet's Survival, Evasion, Resistance and Escape (SERE) school were both named in his honor. In July 2008, a statue of him was erected in front of Luce Hall at the U.S. Naval Academy; the hall which houses the Vice Admiral James B. Stockdale Center for Ethical Leadership.[22]

The Admiral James & Sybil Stockdale Arena at South Kent School was named after Stockdale and his wife in April 2014.[24]

In October 2014, Airbase Arizona of the Commemorative Air Force placed on display a lovingly restored GrummanAF-2S Guardian (s/n 126731) flown by VAdm Stockdale early in his Navy career with his name on the canopy rail and all markings as they were when he flew the aircraft in the 1950s.

Stockdale's naval experiences and his leadership decisions while senior Naval officer in prison in North Vietnam are an integral part of every Midshipman's educational experience at Annapolis.

A luxury suite at the Loews Annapolis Hotel, where Perot announced his candidacy, was named in Stockdale's honor.

For conspicuous gallantry and intrepidity at the risk of his life above and beyond the call of duty while senior naval officer in the Prisoner of War camps of North Vietnam. Recognized by his captors as the leader in the Prisoners' of War resistance to interrogation and in their refusal to participate in propaganda exploitation, Rear Adm. Stockdale was singled out for interrogation and attendant torture after he was detected in a covert communications attempt. Sensing the start of another purge, and aware that his earlier efforts at self-disfiguration to dissuade his captors from exploiting him for propaganda purposes had resulted in cruel and agonizing punishment, Rear Adm. Stockdale resolved to make himself a symbol of resistance regardless of personal sacrifice. He deliberately inflicted a near-mortal wound to his person in order to convince his captors of his willingness to give up his life rather than capitulate. He was subsequently discovered and revived by the North Vietnamese who, convinced of his indomitable spirit, abated in their employment of excessive harassment and torture toward all of the Prisoners of War. By his heroic action, at great peril to himself, he earned the everlasting gratitude of his fellow prisoners and of his country. Rear Adm. Stockdale's valiant leadership and extraordinary courage in a hostile environment sustain and enhance the finest traditions of the U.S. Naval Service.[25]

Apart from the works written by Stockdale himself, the following work refers extensively to Stockdale's involvement in the Tonkin Gulf:

Edwin E. Moise, Tonkin Gulf and the Escalation of the Vietnam War UNC Press North Carolina 1996 ISBN 0-8078-2300-7

The following book is based on the series of lectures delivered for the course in moral philosophy established at the Naval War College by Admiral Stockdale in 1978, when Stockdale was president of the college. The course was designed by Stockdale and Professor Joseph Brennan, who continued to teach it after Stockdale retired from the Navy. The Foreword was written by Stockdale.