I would say no western sword beat the katana, except perhaps the rapier. The rapier is lighter than the katana and offers longer reach, but is less defensively versatile (it is very difficult to use at extreme close range, and is too light to block more powerful blows). A fight of this type has been staged before, pitting masters in fencing and kenjutsu against each other. In the end, the fencer hit the samurai in the chest at the same time the samurai came down on the fencer's left shoulder. While both would have died eventually (if they were using real weapons), the samurai would have cleaved the fencer in half, killing him almost immediately, while the samurai himself would bleed to death in several minutes.Mad Maniac with axe-firing chainsaw said:The cutlass is weaker than the katana while being single-edged (throwing away, quite literally, the edge western swords had over katanas on being double-edged, an important advantage...
Whether or not medieval Japan had a navy is irrelevant. The ninja would never use a fleet to combat a fleet with 100 years of technological advantage, this would be a samurai tactic, if used at all. The ninja would instead infiltrate the pirate fleet, one ship at a time, under cover of darkness (and "rum goggles"). I think the ninja would have been able to infiltrate pirate ships relatively easily, especially at night. When the pirate ship moored, the ninja could swim out to it (the ninja had access to a variety of breathing tubes and inflatable skins to ease this process, though being soaking wet might be a disadvantage), or take a small collapsible boats (Draeger and Smith, Comprehensive Asian Fighting Arts) out to it. Various wooden shoes that supposedly allowed a ninja to walk over water have been suggested, but Mythbusters has disproved the feasibility of the most practical variant. Once there, a single ninja could wreak havoc among the drunken crew, silently slitting all of their throats, or better yet, poisoning the rum supply or blowing the powder hold.Mad Maniac with axe-firing chainsaw said:On the other hand, ninjas would get trounced if they were forced to engage pirates on sea. Medieval Japan didn't have a navy to speak of...
The samurai, though they are generally regarded as less powerful than ninja due to their lack of stealth, do have some advantage over ninjas when fighting pirates. An assassination attempt on Oda Nobunaga, which was conducted by a ninja sharpshooter named Sugitani Zenjubo armed with an arquebus (a lighter predecessor of the musket, used from 1400-1600), was foiled when both shots failed to penetrate Oda's armor. The period of piracy in the Caribbean essentially lasted from 1523 to 1725 (For reference, Blackbeard was active as a pirate from 1713 until his death in 1718), so the pirates would have only marginally better firearms than the the ninja sharpshooter, and their projectiles would be slowed or stopped by the armor, causing insignificant short-term damage.
So, magical ninja powers aside, ninja would probably still beat pirates in any situation, assuming the ninja could preserve their advantage of stealth. If the pirates were all awake, sober, and armed with a brace of pistols when a ninja attacked, and the pirates could see the ninja, the ninja would probably end up riddled with lead balls.
Also, Miyamoto Musashi was a samurai, and he could defeat any pirate even armed with an oar. Batman was trained as a ninja, and look how often he defeats people with guns.
It may be more interesting to expand the view of pirates and ninja beyond their traditional time settings. Modern pirates, for example, are some of the most laughably ill-equipped criminals in the world, yet still occasionally manage to thwart military efforts to stop them. Modern ninja and samurai are less common in combat environments, though one might say a special forces operative that focuses on stealth and a spy that performed espionage/sabotage in person (rather than with a computer) are both examples of modern ninjas. Both pirates and ninjas can be taken far into futuristic settings, with "space pirates" etc., though at this point the combat advantages and disadvantages of both sides are purely speculative.