The Japanese Samurai weren't really known for attacking western forces, even the Ronin, however a band Japanese pirates did on one such occasion in history.
The Wokou were a band of Japanese pirates mostly made up of Ronin samurai, as well as other pirates of the region who routinely attacked ports across China, Korea and Asia in general.
In the latter part of the sixteenth century, the Wokou began their pirate ways upon the citizens of the Spanish controlled Philippines, where they routinely treated the natives quite harshly.
Carrión, commander of the Spanish Navy in the region, took the first step by sinking one of the pirates ships'. The leader of the pirates, Tay Fusa, retaliated by sending 10 ships into the island group off the Philippine coast, the Spanish gathered what they could in defence, which included forty soldiers, seven boats, five support vessels, a light ship and a galley. They were still heavily outnumbered by the pirates.
When the Spanish observed a pirate ship on the coast of Bogueador Cape, the commenced a naval battle with the Japanese and boarded the pirate ship, despite being outnumbered by the pirates. A fierce battle raged on the deck but was eventually won by the Spanish.
The Spanish fleet continued down the river and came across 18 more pirate vessels, despite the numbers of the pirate fleet, the Spanish were well positioned using their artillery against the pirates.
As a result the Japanese attempted to negotiate a surrender with the Spanish, the Spanish asked them to leave, but the pirates wanted compensation for leaving the island, which the Spanish refused.
The Japanese response was to send 600 soldiers to attack by land, even though the Spanish were entrenched, but the Spanish only had 30 soldiers to defend with. The Spanish soldiers in the trenches survived multiple waves of attack from the Japanese, and after the third wave of attacks the Spanish were able to defeat the pirates, and in turn attacked them which caused the pirates to flee.
The Spanish suffered minimal losses while killing hundreds of the pirate fleet. Spanish reinforcements arrived soon after to pacify the region, pirate activity in the area was not really felt after that.