A high-seas drama with Kalashnikov and rocket- propelled grenade fire gripped a Rome courtroom at the trial of alleged Somali pirates Tuesday, as EU forces blasted a pirate base for the first time.

"We're alive by a miracle," said an emotional Stefano Mariotti, a crew member on board the Italian-flagged Montecristo cargo ship when it came under attack by pirate speedboats off the coast of Somalia on October 10, 2011.

Mariotti and the 22 other crew members managed to avoid being taken hostage by the pirates by sealing themselves in a special area of the engine room and overriding the pirates' attempts to steer the ship towards Somalia.

"I sent an SOS signal from our satellite phone. When we saw them loading a second grenade, we ran to the citadel," said Mariotti, looking at the eight suspected pirates behind bars on the defendants' benches.

The first grenade hit the Montecristo's chimneystack -- the second one detonated a few second later after the crew fled, blowing up the bridge.

The crew remained locked for more than 24 hours with no contact with the outside world, as the pirates used explosives and crowbars to try to force their way in and even lit fires to try to force the crew members out.

The Montecristo was eventually spotted by US and British warships alerted by an Italian navy destroyer, the Andrea Doria, which had first received news of the hijacking and took command of the rescue as part of a NATO operation.

When crew members saw a US helicopter circling overhead they scrawled signs saying they had not been taken hostage and asking for an armed intervention. They held the signs up through a ventilation shaft in the chimneystack.

They even scrawled a message in a bottle and threw it into the sea.

When they saw the warships approaching, the pirates dumped their weapons, surrendered and were eventually arrested on the Andrea Doria after a hearing with Italian prosecutors via video link, military personnel told the court.

The suspected pirates -- many of them lanky youngsters in tracksuit tops and freshly pressed shirts -- hunched over in concentration as a Somali interpreter translated parts of the hearing in a vast courtroom used for mafia trials.

They are accused of hijacking and suspected kidnap with "a possible terrorist intent" as prosecutors argue that the ransom money they wanted was intended to fund the Shebab militant group which controls much of Somalia.

They face up to 20 years in prison. The defence argues that they are innocent fishermen and were forced to board the Montecristo.

Mariotti told AFP after the hearing that he felt no pity for the accused.

"They shot a bazooka at me! They say they're fishermen but what were they fishing then out there in the open sea? Moby Dick?"

Domenico Guglielmi, the commander of the Andrea Doria, said: "Don't let yourselves be fooled. It's different when they have guns."

Guglielmi praised the crew for their quick reaction time and for managing to take pictures of the pirates still with their guns.

"I wouldn't define these as simple pirates. They managed to board a ship protected by barbed wire which was travelling at 15 knots and they also managed to take control of it on two occasions," he told the court.

As international powers ramp up their efforts to protect vital shipping lanes from Somali piracy, a helicopter gunship also on Tuesday swooped over the Somali coast to strike at a pirate stronghold in the first such attack.

NATO and European Union warships have battled pirates at sea since 2008 and the EU says eight vessels and 235 sailors are currently still held hostage.

Several countries including France, Kenya, South Korea and the United States have tried pirates but the case in Italy is one of the biggest of its kind.

Guglielmi said that after the Montecristo's crew were released, the warships launched a hot pursuit to find the "mother ship" from which the pirates came.

They eventually found a fishing boat with more guns and communication equipment on board, as well as special ladders with hooks for boarding vessels.

Eleven Somalis were arrested on the Montecristo and four on the second boat -- some are being tried as minors and one has opted for a fast-track trial.

Mariotti said he was now headed for South Africa to board the Montecristo for another voyage through pirate-infested waters on the way to the Suez Canal.

"What can you do? Work is work," he sighed as he walked from the courtroom.