The frigate dispatched a helicopter which together with another chopper from the US naval ship Monterey stopped the attempted attack by firing warning shots.
The US helicopter then returned to its ship and the Rheinland-Pfalz steamed the 50 nautical miles to the area, boarded the pirates' vessel and took the nine into custody, the German military said.
"They are currently being questioned about who they are and their activities," it said.
The container ship in question was the MV Courier, sailing under the flag of Antigua and Barbuda.
More than 100 vessels were attacked last year by pirates in the Gulf of Aden which is now patrolled by naval warships from the United States, EU and other countries including China to protect vessels in the vital waterway.
In November, pirates captured the world's attention when they hijacked the Saudi-owned super-tanker Sirius Star, carrying two million barrels of crude oil, and demanded a 25-million-dollar ransom for the ship and its crew.
The pirates, heavily armed and using high-powered speedboats, prey on a key maritime route leading to the Suez Canal, through which an estimated 30 percent of the world's oil transits.
They are believed to number around 1,200 former and seasonal fishermen and coast guards, many of them from lawless Somalia, which has been ravaged by years of conflict and starvation.