Appointed a second lieutenant in the US Marine Corps on 18 January 1801, he served in various stations in the United States prior to assignment aboard USS Adams. Following a deployment to the Mediterranean in Adams, now-First Lieutenant O’Bannon returned to the United States in November 1803, and was assigned to duty at Marine Barracks, Washington DC.
In 1804, Lt. O’Bannon was again called to sea duty, this time aboard frigate USS President. Setting sail for the Mediterranean in May 1804, the President arrived at Gibraltar in August. Following several months in the Mediterranean, Lt. O’Bannon was transferred to frigate Constitution, and then to USS Argus. While there, he was selected for a mission that later was commemorated in the colors of the Marine Corps and recorded in the Marine Hymn in the words “to the shores of Tripoli.”
For many years the United States had maintained peace with the Barbary States by “buying” treaties and paying tributes to the Pasha. The states of Algiers, Morocco, and Tunis remained reasonably complacent under this system, though Tripoli continued to demand larger payments and make threats against the United States.
Finally, on 14 May 1801, the Pasha of Tripoli, Yousuf, demonstrated his dissatisfaction by cutting down the flagstaff in front of the US consulate. This led to a declaration of war by the United States and more warships being dispatched to the Mediterranean. During a storm, one of these, frigate Philadelphia, went on the rocks off Tripoli, with her crew being captured and imprisoned at Derne.
This event and the inability of US agents to ransom the crew of Philadelphia led to the formation of a bold rescue plan, which included Lt. O’Bannon. The plan, conceived by naval agent William Eaton, proposed the formation of an alliance with Hamet, elder brother of Yousuf.
In January 1805, Lt. O’Bannon, in command of a marine detachment consisting of one sergeant and six privates, joined Eaton’s allied force at Alexandria, Egypt. This motley hoarde of 500 mercenaries and soldiers of fortune then began an overland expedition against Derne. There, on 27 April 1805, with bombardment support provided by Hornet, Nautilus, and Argus, Lt. O’Bannon led his force through a hail of musketry and stormed the principal edifices. The enemy was routed in such haste that they left their guns loaded and primed. Lt. O’Bannon planted the United States flag upon the ramparts, then turned the guns upon the enemy. The stronghold was occupied after some two hours of hand-to-hand fighting, and for the first time in history the flag of the United States flew on foreign soil.
The Tripolitans counterattacked the fortress a number of times, but were repelled with heavy losses. Finally, through a spirited bayonet charge, the enemy was driven from the vicinity of Derne. This stubbornness and pugnacity by the Americans led to an almost mythical belief in their fighting ability.
On the occasion of his departure, Hamet honored Lt. O’Bannon by presenting him his jeweled sword with a Mameluke hilt. This sword was the model for the dress sword used by Marine Corps officers today, making it the oldest continuously used weapon in the US military arsenal. Upon his return to the United States, the state of Virginia presented O’Bannon a sword modeled after the original Mameluke blade given him by Hamet.
Hailed as the “hero of Derne,” Lt. O’Bannon resigned from the Marine Corps on 6 March 1807. He retired to Logan County, Kentucky and served in the state legislature. He died on 12 September 1850 at the age of 74. In 1919, his remains were removed to the State Cemetery in Frankfort, Kentucky, where a monument is erected in his memory.