The protagonist is the sharp-witted Dr. Peter Blood, a fictional Irish physician who had had a wide-ranging career as a soldier and sailor (including a commission as a captain under the Dutch admiral De Ruyter) before settling down to practice medicine in the town of Bridgwater in Somerset.
The book opens with him attending to his geraniums while the town prepares to fight for the Duke of Monmouth. He wants no part in the rebellion, but while attending to some of the rebels wounded at the Battle of Sedgemoor, Peter is arrested. During the Bloody Assizes, he is convicted by the infamous Judge Jeffreys of treason on the grounds that "if any person be in actual rebellion against the King, and another personâwho really and actually was not in rebellionâdoes knowingly receive, harbour, comfort, or succour him, such a person is as much a traitor as he who indeed bore arms."
The sentence for treason is death by hanging, but King James II, for purely financial reasons, has the sentence for Blood and other convicted rebels commuted to transportation to the Caribbean, where they are to be sold into slavery. Upon arrival on the island of Barbados, Blood is bought by Colonel Bishop, initially for work in the Colonel's sugar plantations but later hired out by Bishop when Blood's skills as a physician prove superior to those of the local doctors. During his period of slavery, Blood becomes acquainted with and even friendly with Arabella Bishop, Colonel Bishop's niece, who becomes sympathetic after learning his history.
When a Spanish force attacks and raids the town of Bridgetown, Blood escapes with a number of other convict-slaves (including former shipmaster Jeremy Pitt, the one-eyed giant Edward Wolverstone, former gentleman Nathaniel Hagthorpe, former Royal Navy petty officer Nicholas Dyke and former Royal Navy master gunner Ned Ogle), captures the Spaniards' ship and sails away to become one of the most successful pirates in the Caribbean, hated and feared by the Spanish and always sparing English ships. Colonel Bishop, humiliated by Blood's escape and by Blood himself, devotes himself to capturing Blood with the hope of hanging him.
After the Glorious Revolution, Blood is pardoned. As a reward for saving the colony of Jamaica from a French assault, he is appointed its governor in place of Colonel Bishop, who had abandoned his post to hunt for Blood, and the novel ends with the implication that Blood will not only marry Colonel Bishop's niece Arabella but will also let Bishop off easy.

Question: How does Peter Blood escape Bridgetown?
Answer: During a spanish pirate raid.
Alternative answer: during a Spanish attack on the island