"The seven Danes have been released and brought to safety," the ministry said in a statement, adding that all were doing well under the circumstances.
No details were provided on the release, but Danish press reports suggested a ransom had been paid.
The Johansen family, a couple in their 50s and their three teenage children, and two guests had been sailing some 300 nautical miles from Somalia when they were seized by pirates on February 24.
They were reportedly moved to the mountain village of Hul-Anod in the restive northeastern Puntland region of Somalia in March, but after a failed attempt by government troops to free them they were transferred to the pirates' mother ship, a Greek vessel captured earlier.
Jan Qvist Johansen, his wife Birgit Marie, and their three children aged 13 to 17 years old left Denmark in August 2009 on a round-the-world trip by yacht. They had initially planned to return at the end of this summer.
The Danish foreign ministry said Wednesday that the pirates were still holding six sailors, two Danes and four Filippinos, from the seized cargo ship, Leopard.
"Danish authorities are following this matter very closely," the ministry said.
Sign up here with your email