WASHINGTON — The deal that freed an American jailed in Cuba and ended 53 years of diplomatic estrangement between the United States and Cuba was blessed at the highest levels of the Holy See but cut in the shadowy netherworld of espionage.

A personal appeal from Pope Francis, American officials said, was critical in persuading Cuba’s president, Raúl Castro, to agree to a prisoner swap and the freeing of the American aid worker Alan P. Gross. The pope, officials said, acted as a “guarantor” that both sides would live up to the terms of a deal reached in secret.

The most tangible breakthrough, however, came almost a year into the talks, when the United States, at loggerheads with Cuba, proposed to swap three Cuban agents jailed in the United States for a Cuban working for American intelligence who had been held in a jail in Cuba for nearly 20 years.

By introducing another figure to the talks — the kind of horse-trading that was standard in Cold War spy swaps — the White House was able to sidestep the appearance that it was trading Cuban spies directly for Mr. Gross. Cuba had sought a straight swap but the United States resisted, saying Mr. Gross had been wrongfully imprisoned.