The Fortune of War by Patrick O'Brian
Patrick O'Brian's Aubrey-Maturin tales are widely acknowledged to be the greatest series of historical novels ever written.
Captain Jack Aubrey, RN, arrives in the Dutch East Indies to find himself appointed to the command of the fastest and best-armed frigate in the Navy. He and his friend Stephen Maturin take passage for England in a despatch vessel. But the war of 1812 breaks out while they are en route. Bloody actions precipitate them both into new and unexpected scenes where Stephen's past activities as a secret agent return on him with a vengeance.