The most famous example of this would be Blackbeard's defeat. The Wikipedia article is quite thorough, so I'll focus on the last battle. The local governor organized a pirate hunt to capture or kill Blackbeard after he started pirating again (Blackbeard was pardoned shortly before).
Two sloops found Blackbeard's vessel anchored at Ocracoke island. The whole situation was quite fortuitous for the hunters. Blackbeard didn't post a sentry, so didn't notice the enemy until they engaged and more than half his crew was at Bath (a town on the mainland, around 120km from the island).
The three vessels engaged in combat next morning. The account of what happened in the naval battle is a bit muddied. A broadside from Blackbeard's vessel heavily damaged and killed nearly 20 men on Maynard's ship and completely disabled its compatriot. Meanwhile Blackbeard ran aground on a sandbank, also taking heavy damage, it's unclear whether damage done by the British sloops caused this. Blackbeard then decided to board Maynard's vessel. Maynard kept most of his men below deck, so Blackbeard was lulled into a false sense of security seeing the many dead on deck and not expecting to see much resistance. After boarding, the pirates were surprised by Maynards men storming from below deck and while the pirates were able to inflict quite a few casualties, they were outnumbered. Eventually Blackbeard was surrounded and cut down after which the remaining pirates surrendered.