WASHINGTON — In a rare softening of hostile relations, the White House said Saturday that Venezuela freed seven Americans imprisoned in the South American country and the United States released two nephews of President Nicolas Maduro’s wife who had been jailed for years on drug smuggling convictions.

The swap of the Americans, including five oil executives held for nearly five years, is the largest trade of detained citizens ever carried out by the Biden administration.

“These individuals will soon be reunited with their families and back in the arms of their loved ones where they belong,” President Joe Biden said in a statement.

The White House said Biden had spoken with the families and that the men were in stable health and have been offered a range of support services, including medical care.

Maduro’s government said in a statement that it was releasing the American citizens as a humanitarian gesture. It praised the diplomacy that resulted in the freeing of the two Venezuelans “unjustly imprisoned” in the United States and said it “hopes for the preservation of peace and harmony with all the nations of our region and the world.”

The exchange amounts to an unusual gesture of goodwill by Maduro as the socialist leader looks to rebuild relations with the U.S. after vanquishing most of his domestic opponents. The deal follows months of back channel diplomacy by Washington’s top hostage negotiator and other U.S. officials — secretive talks with a major oil producer that took on greater urgency after sanctions on Russia put pressure on global energy prices.

Those freed include five employees of Houston- based Citgo — Tomeu Vadell, Jose Luis Zambrano, Alirio Zambrano, Jorge Toledo and Jose Pereira — who were lured to Venezuela just before Thanksgiving in 2017 to attend a meeting at the headquarters of the company’s parent, state-run oil giant PDVSA. Once there, they were hauled away by masked security agents who busted into a Caracas conference room.

Also released was Matthew Heath, a former U.S. Marine corporal from Tennessee who was arrested in 2020 at a roadblock in Venezuela on what the State Department has called “specious” weapons charges, and a Florida man, Osman Khan, who was arrested in January.

The U.S. freed Franqui Flores and his cousin Efrain Campo, nephews of “First Combatant” Cilia Flores, as Maduro has called his wife. The men were arrested in Haiti in a Drug Enforcement Administration sting in 2015 and taken to New York to face trial. They were convicted the following year in a highly charged case that cast a hard look at U.S. accusations of drug trafficking at the highest levels of Maduro’s administration.

Both men were granted clemency by Biden before the release.

At least four other Americans remain detained in Venezuela, including two former Green Berets involved in a slapdash attempt to oust Maduro in 2019, and two other men who, like Khan, were detained for allegedly entering the country illegally from neighboring Colombia.

The oil executives were convicted of embezzlement last year in a trial marred by delays and irregularities. They were sentenced to between eight and 13 years in prison for a never- executed proposal to refinance billions in the oil company’s bonds. Maduro at the time accused them of “treason,” and Venezuela’s supreme court upheld their sentences earlier this year. The men all pleaded not guilty and the State Department has regarded them — and the two other Americans freed on Saturday — as wrongfully detained.