An accused pirate who was allegedly part of a Somali crew that kidnapped an American journalist and held him hostage on a hijacked ship while demanding a $20 million bounty was hauled before a federal judge in Brooklyn Wednesday.

Abdi Yusuf Hassan, 51 — who is accused of negotiating the writer’s ransom during his years-long capture — was denied bail while facing six charges, including kidnapping and hostage-taking conspiracy raps, with the judge deeming him too dangerous to be released from the brig.

“I find that the government has amply met its burden of proving that the defendant is a flight risk and a danger to the community,” Judge Allyne Ross said while shooting down his $1 million bail request.

The kidnapped journalist is not named in court documents, but has been identified as German American man Michael Scott Moore, who published a book last year about his ordeal titled, “Desert and the Sea: 977 Days Captive on the Somali Pirate Coast.”

During Moore’s ordeal, Hassan — a naturalized US citizen born in Somalia — allegedly served as a translator, instructing him to urge his family to sell their house to pay his bounty, and helped facilitate gun-point “proof of life” videos, according to court papers.

The writer was researching a book about pirates on the Somali coast in January 2012 when a group of men holding assault rifles and rocket-propelled grenade launchers surrounded his vehicle in Galkayo, according to the court papers.

During the kidnapping, Moore was pistol-whipped, suffered head injuries and a broken wrist — and witnessed the torture of other hostages, according to court documents.

The gang of roughly 10 outlaws then held him at several spots around the country for two and a half years, including on a hijacked fishing ship.

In May 2012, the pirates released a video showing the journalist at a mystery location with a prayer shawl over his head, surrounded by masked kidnappers pointing a machine gun at him.

The next year, Moore was moved to a home near Galkayo, where Hassan — whose lawyer says he is a former state minister of the interior and security in his homeland — regularly visited him, according to a criminal indictment.

Moore was finally freed in 2014 after his family forked over $1.6 million for his release.

According to the complaint, Hassan first came to the US in the 1990s and has returned multiple times since, in 2015 telling US Customs and Border Protection that he was a government minister in Somalia who had worked to arrange for the release of kidnapped people — including the journalist.

He was arrested in Minneapolis after returning to the States earlier this year, where his local friends showed up at court to insist he’s innocent, according to a local CBS report at the time.

On Wednesday, Hassan’s defense attorney, James Kousouros, insisted his client actually worked with Somali government officials to stop pirates.

“He has put himself out there as someone who is the antitheses of the hostage-taking situation in Somalia,” Kousouros said.

Another one of the accused pirates, Mohammed Tahlil, was arrested in November and is also awaiting trial before the same Brooklyn judge.

Moore declined to comment.