WASHINGTON — President Obama on Wednesday ordered the restoration of full diplomatic relations with Cuba and the opening of an embassy in Havana for the first time in more than a half-century as he vowed to “cut loose the shackles of the past” and sweep aside one of the last vestiges of the Cold War.

The surprise announcement came at the end of 18 months of secret talks that produced a prisoner swap negotiated with the help of Pope Francis and concluded by a telephone call between Mr. Obama and President Raúl Castro. The historic deal broke an enduring stalemate between two countries divided by just 90 miles of water but oceans of mistrust and hostility dating from the days of Theodore Roosevelt’s charge up San Juan Hill and the nuclear brinkmanship of the Cuban missile crisis.

“We will end an outdated approach that for decades has failed to advance our interests, and instead we will begin to normalize relations between our two countries,” Mr. Obama said in a nationally televised statement from the White House. The deal, he added, will “begin a new chapter among the nations of the Americas” and move beyond a “rigid policy that is rooted in events that took place before most of us were born.”