Q Boats
I was thinking exactly the same thing.
Here’s my idea. A Navy destroyer steams up alongside a merchant vessel, transfers over a squad or two of Marines with anti-tank rockets and heavy machine guns.
The Marines settle in at strategic locations around the hull.
Pirate comes barrelling up on the merchie, Marines blow said pirates to hell and gone.
Since there is no way for the pirates to know which merchie is carrying the Marines, they have to assume that any merchie they approach might have them aboard. Two or three pirate boats get blown out of the water and it might give the rest the idea that a different career choice might not be a bad idea.