A provocative article about US veterans killed during a deadly 1935 hurricane in the Florida Keys brought Ernest Hemingway, journalist and best-selling author of “The Sun Also Rises” and “A Farewell to Arms,” to the attention of Soviet intelligence. The veterans had been hired by the Roosevelt administration to build a bridge, and Hemingway, a Key West resident who had been an ambulance driver in Europe during World War I, discovered their corpses while cruising in his boat, named Pilar.

“Hemingway had not seen so many dead men in one place since 1918,” writes Nicholas Reynolds in his new book, “Writer, Sailor, Soldier, Spy.” Hemingway was so outraged by the way they were treated, their rotting bodies left in the water, he wrote an incendiary article about the debacle for the niche Marxist magazine New Masses. The piece also got noticed by Soviet intelligence, which tracked potential foreign sympathizers to the Communist cause.

Reynolds’ book describes Hemingway’s “conversion experience” as a result of this tragedy. From the Spanish Civil War to the end of World War II, he would become a champion of the oppressed, using his reputation as a celebrated novelist and journalist to fight fascism. It was a stance that made him a desirable candidate for both Soviet espionage and American intelligence operations. And Hemingway — maintaining his status as a free agent while stoking his ego — flirted with both sides.

Eventually, Hemingway would attract the attention of the NKVD, or People’s Commissariat for Internal Affairs, a precursor to the KGB. “It was the Soviet Secret Service — the CIA and FBI rolled into one,” Reynolds tells The Post.

When Hemingway went to Spain in 1937 to cover the Spanish Civil War for the North American Newspaper Alliance — leaving behind his second wife, Pauline, and traveling with his new mistress, journalist Martha Gellhorn — he met openly with Soviet figures, Communist commanders, journalists and spies at Madrid’s Gaylord Hotel.

“He loved having this edge, having access other journalists wouldn’t have had,” Reynolds says. “He was meeting the cream of the international Communist movement.”

As Hemingway’s anti-fascist fervor increased, he became a more attractive figure to the Communists. It didn’t hurt that he was also a celebrity, the most prominent journalist in Spain. In 1937, Hemingway sought to learn more about the Republic guerrillas fighting Gen. Francisco Franco’s Nationalists, who were supported by both Nazi Germany and Fascist Italy.

According to Reynolds, Hemingway visited Benimamet, “a secret guerrilla camp in the NKVD domain,” with Alexander Orlov, a general in the Soviet Secret Police and an NKVD “rezident.” There, Orlov and Hemingway fired Soviet weapons and downed vodka at lunch.

That successful visit helped facilitate Hemingway’s four-day stint with the Communist guerrillas, during which he observed an attack on a Nationalist train. The incident would later drive the plot of Hemingway’s masterpiece, 1940’s “For Whom the Bell Tolls.”

Barcelona fell to Franco in January 1939. By March, Hemingway moved to Cuba with Gellhorn and threw himself into finishing “For Whom the Bells Tolls.” While Hitler was invading Poland in September of that year, Hemingway was finalizing his divorce. He married Gellhorn in November 1940.

Around that time, Hemingway met with Jacob Golos, an old Bolshevik who was charged by Moscow with recruiting him for the NKVD.

As an anti-fascist, Hemingway was considered pro-Soviet and an ideal candidate to gather information or serve as a scout for new recruits.

The novelist was given the code name Argo — the name of the ship used by Jason and the Argonauts in Greek mythology — and a copy of “For Whom the Bell Tolls” was added to his file in Moscow.

On their honeymoon in New York, Gellhorn was assigned a story by Collier’s magazine to report on the Second Sino-Japanese War. Hemingway went along, wrangling his own freelance assignment for the leftist tabloid PM. US Treasury Secretary Henry Morgenthau Jr. sought Hemingway’s services at this time. He wanted Hemingway to report back general observations on Chinese leadership — which the United States was helping to finance.

For Hemingway, Reynolds writes, “this was the kind of recognition he craved. In his mind, he was more than just a novelist or a journalist: He was a sophisticate who understood how the world worked and could use his understanding to help shape events.”

As an anti-fascist, Hemingway was considered pro-Soviet and an ideal candidate to gather information or serve as a scout for new recruits.

In China, Hemingway’s celebrity would again admit him into the inner circle of society. But Reynolds stresses that, strictly speaking, Hemingway wasn’t spying in China. “No one gave up, stole or bought any state secrets,” he writes. “Both the Communists and the [Chinese] Nationalists used him to deliver their messages to the American public and the American government, while [Morgenthau] got a personal briefing.”

Hemingway was at a turning point, Reynolds says. His ability to maneuver in international circles was based on his stature as a writer, so how was he going to work in a secret identity as a spy?

“Almost immediately, he has buyer’s remorse,” says Reynolds. “He knows he needs to have clandestine meetings but has second thoughts. [He’s thinking], ‘My job is to be the great American writer, and he adopts an arm’s-length approach.’ ”

For Hemingway, the fact that the US government, after ignoring him during the Spanish Civil War, sought his views was enormously gratifying and he felt comfortable making policy recommendations, in particular that the US should not finance a civil war in China.

An invitation to visit Moscow was extended by Soviet Foreign Minister Vyacheslav Molotov (for whom the incendiary “cocktail” is named) in 1941 for the putative purpose of collecting “a large sum of rubles” representing royalties from the sales of Hemingway’s books, but it was likely a pretext, Reynolds argues, for getting the NKVD to spend more time “training” him.

Hemingway never made it the Soviet Union, though. Pearl Harbor was bombed on Dec. 7, 1941, and all bets were off. “Now the US is on the anti-fascist team,” says Reynolds. “Then he sees if he can do things for the US.”

In fact, Hemingway offered to set up a counterintelligence agency in Havana for US diplomat Robert Joyce. He discussed the idea with Joyce’s boss, US Ambassador to Cuba Spruille Braden, who immediately grasped Hemingway’s potential to mobilize “a bizarre combination of bartenders, wharf rats, down-at-heel pelota players, former bullfighters and Basque priests,” among others, to work as informants.

Known as the Crook Factory, they went to work in 1942 on a budget of $500 per month. Conventional intelligence gatherers in Washington, DC, were skeptical of Hemingway’s ragtag group, but Braden was supportive. And his gambit paid off.

On Dec. 9, 1942, Hemingway reported a U-boat sighting, and the Navy “took it seriously enough to retransmit the fleet and pay him and his crew a small compliment.” According to Reynolds, Braden believed “Hemingway made a real contribution to the war effort,” sending an effusive note to the “sailor-spy for taking ‘personal risks’ despite the ‘ever-present danger.’ ”

Hemingway, whom Reynolds calls a “self-guided missile,” achieved true heroism in World War II, where he traveled as a correspondent to report on the conflict from the Royal Air Force’s perspective, with Col. David K.E. Bruce, the senior commander in Europe for the Office of Strategic Services, forerunner of the CIA. Together, they outwitted the Germans outside Paris. Hemingway even saved the life of a young Andy Rooney, the late “60 Minutes” correspondent, who was a reporter for Stars and Stripes. Hemingway was awarded a Bronze Star for bravery in 1947.

After the war, when he was back living in Cuba, Hemingway wrote to his closest military buddy, Col. Charles T. Lanham, that he was “absolutely homesick for the regiment.” In his letter, he called ground combat the “ultimate” life experience.

“It is wicked to say, but that is the thing I love . . . best.”

For the writer, sailor, soldier and spy, the fight was the thing.

Writes Reynolds, “He felt most alive when risking his life, all of his senses fully engaged, putting his well-developed field and military skills to good use and not incidentally killing fascists.”