Dunkirk was occupied by English forces of The Protectorate in 1658, when it was captured from Spain by Anglo-French forces following the Battle of the Dunes. The Spanish forces included British Royalist Regiments: The (English) King's Guards(foot) under Wentworth; A Scottish Regiment under Newburgh; The Marquis of Ormond's (Irish) Regiment under Richard Grace; The Duke of York's (Irish) Regiment under Muskerry; The Duke of Gloucester's (Irish) Regiment under Taaffe; and Farrell's (Irish) Regiment under Lisagh Farrell.
The regiments (except, perhaps, Ormond's) were seriously understrength and were all under the overall command of James, Duke of York. There was also a small contingent of James' own Life Guards. The English part of the Anglo-French force included regiments under William Lockhart, Thomas Morgan, Roger Alsop, Samuel Clark, Bryce Cochrane and Roger Lillingston. 
France, effectively ruled by Mazarin, had promised, as part of the Treaty of Paris (1657) that Dunkirk and Mardyke, then in the Spanish Netherlands, would be ceded to England. Mazarin honoured that pledge after the victory at The Dunes, and Louis XIV himself delivered Dunkirk over to Lockhart (who was Cromwell's Ambassador to France) on or about 24 June 1658.  Cromwell appointed Lockhart Governor of the town.
Lockhart's regiment, much reduced in the battle, and Alsop's garrisoned Dunkirk and Mardyke (now Fort-Mardyck), taken in 1657, reinforced by Salmon's and Gibbon's regiments from England, but Morgan's, Clark's, Cochrane's and Lillingston's continued to serve with the French Army in Flanders. The Royalist regiments, even more reduced by the defeat, continued to serve with Spain.  In early 1659, most of Salmon's regiment was sent back to England, as was Gibbon's, and three regiments of the Protectorate force (Morgan's, Clark's, Cochrane's) returned to England in August 1659 in response to (planned, but discovered) Royalist uprisings culminating in Booth's uprising.
The Treaty of the Pyrenees in November 1659 confirmed English possession of Dunkirk, which then passed to Charles following the Restoration in 1660. The merchant Edward Blackwell, who served as Treasurer of Dunkirk under both the Republican and Royal governments, was instrumental in the sale. 
In 1662, King Charles II, short of money and concerned that Dunkirk was a potential liability for international relations, sold it to France. The purchase price was five million livres. Many in England were opposed to the loss. 
Since 1660, Dunkirk had been garrisoned by an uneasy mixture of English former New Model Army troops of republican sympathies and several Royalist regiments who had served under Charles in exile, which included many Irish Catholics. Many of the garrison of Dunkirk were shipped to English Tangier, which had recently been acquired as part of the Marriage Treaty with Portugal, where they formed most of the initial Tangier Garrison.  Also many from the garrison joined the British brigade to fight in Portugal to help with her war of restoration against Spain. 
- Firth, C H (1902). "Royalist and Cromwellian Armies in Flanders, 1657-1662". Transactions of the Royal Historical Society. New. XVII: 67.
- Plant, David (2008). "Flanders, 1657-8". BCW Project. Retrieved 10 July 2016.
- Uglow p.203-4
- 27 October 1662: England sells Dunkirk to France
- Childs p.116-18
- Riley pp 54-56