Jack Barsky kept his calm as he neared the traffic circle underneath the West Side Highway overpass. In his hand he held a piece of chalk and furtively drew a straight horizontal line on the wall as he walked past.

If a pedestrian happened to notice it, they might think it a mark made by a kid, or perhaps nothing it all.

But when a certain undercover KGB operative spotted the chalk mark as he drove from his compound in The Bronx to his cover job at the United Nations, he would inform his comrades, and they would know what it meant: Barsky had reported for duty in New York City.

It was 1978, and the Cold War was in full effect. Barsky was a spy, illegally in the US under a stolen identity. One wrong move could put him at risk, perhaps even send him to prison for the rest of his life.

But, as he writes in his new book “Deep Under Cover: My Secret Life and Tangled Allegiances as a KGB Spy in America” (Tyndale Momentum), out now, the most dangerous thing of all happened: He fell in love with America.

The man who came to be known as Jack Barsky was born Albrecht Dittrich in 1949 in East Germany. One of his earliest memories was listening to radio coverage of Josef Stalin’s 1953 funeral, and his father boasting, “Comrade Stalin was a great man.”

Dittrich joined the Communist party as a college student. His first encounter with the shadowy side of Communism came in 1970, in the form of a knock on his dorm room door. A mysterious man Dittrich assumed was from the Stasi, the East German secret police, asked if he was interested in a government career. Intrigued, Dittrich said yes — and days later found himself meeting with a KGB operative.

“At the time I was recruited, the Soviet Union was arguably at the height of its power,” he writes. “ I had no problem working for the Russians, because they were our big brother and they were leading [East Germany] to the promised land.”

Dittrich entered a KGB training program with the intention that he would one day be embedded undercover in New York. He studied American culture and mannerisms, and English lessons helped erase his accent. He learned how to send and receive coded messages, as well as how to tell if he was being followed and how to set up “dead drops” to exchange money and top secret information with fellow agents.

A KGB agent already ensconced in the States combed over gravestones in a Maryland graveyard to find the perfect all-American identity: Jack Barsky, who had died at the tender age of 10. Another agent posed as Barsky’s father in order to obtain a new birth certificate. Dittrich got a fake Canadian passport, which he used to enter the US.

Once over the border, he discarded the passport and was reborn as an American — Jack Barsky.

By the time Dittrich arrived in New York City with his new identity in October 1978 at age 29, he had boned up as much as possible on Western pop culture.

Barsky landed a job as a bike messenger to create a credible work history and make some money, and got his GED. In 1981, he enrolled at Baruch College, and in just three years earned a degree in computer systems with a 4.0 grade point average. Getting perfect scores was no chore for the man who had earned an advanced chemistry degree and even taught university classes back in Germany.

There was just one thing that made Barsky sweat: As class valedictorian, he would have to give a speech in front of his classmates and their graduation-day guests.

“If my unauthorized public appearance came to the attention of my bosses in Moscow, I could reasonably expect some sort of punishment,” he recalls in the book.

He tried to shrug off this duty, claiming that he was shy. But the dean wouldn’t have it, and Barsky decided he could not turn away from the challenge of his moment in the spotlight. So Jack Barsky, undercover KGB spy, climbed onto one of New York’s biggest stages — Madison Square Garden — and spoke to some 4,000 people as if he were one of them.

He got a job in the information technology department of Metropolitan Life Insurance Co., earning $21,500 a year (which translates to around $50,000 today). The KGB was delighted with his posting.

“Insurance companies were always near the top of the list of capitalist villains in Communist propaganda,” Barsky writes. He quickly advanced within the company, just as his Moscow bosses hoped, and was able to conduct workplace espionage — netting himself a $10,000 from the KGB for transmitting to them software used by MetLife.

The chinks in my ideological armor began to grow into wide open cracks.

But he liked his job, and felt treated well by coworkers. In fact, the KGB spy was getting comfortable in his new American life: “The chinks in my ideological armor began to grow into wide open cracks.”

He was also softened by love, having fallen for an illegal immigrant from Guyana named Penelope. Despite not being an American citizen himself, Barsky wed her in hopes of helping her get citizenship — as it turned out, his driver’s license and birth certificate were the only documents he needed to support that plan.

They moved to Ozone Park, Queens, and Penelope gave birth to their daughter, Chelsea. The little girl immediately became the light of Barsky’s life. He writes, “Love tiptoed up on me.”

It was a familiar feeling; after all, he already had two sons with an ex-girlfriend and a wife back in East Germany. (His other wife knew he was a KGB agent, but little more.)

When the ominous message came from Moscow in December 1988, Barsky ignored it.

“Prepare for urgent departure,” it said. “We have reason to believe that your cover has been blown. You are in severe danger.”

Two weeks later, at the 80th Street/Hudson Street A train station, he spotted a small red dot painted on a support beam — a KGB signal meaning he was to leave the US immediately.

He ignored that message, too.

Days after that, a man approached him on the subway platform. “You must come home or else you are dead,” he told Barsky and walked away.

Barsky was crushed. He loved his wife and daughter. He’d made friends and truly enjoyed his job — he’d even come to prefer the United States over Eastern Europe. Staying in America, he decided, was worth the risk, whether it meant a blown cover, being kidnapped by the bosses or even assassination.

The way out of his dilemma hit Barsky like a thunderclap: he told Moscow he had AIDS.

At the time, AIDS was a death sentence. Barsky signaled that he contracted AIDS from an ex-girlfriend who got it from an earlier boyfriend and claimed he needed to drop out of sight for treatment. He asked his superiors to give his East German wife $60,000 he’d amassed in a KGB bank account. Then he broke contact.

Amazingly, the KGB assumed he died.

“I fully embraced my American existence,” Barsky writes. Soon he and Penelope had a son, Jessie. MetLife transferred Barsky to New Jersey, and the family moved to a house in rural Mount Bethel, PA. Life was good — better than he could’ve dreamed when he left East Germany.

He had no way of knowing his secret was slowly unraveling.

As the Soviet Union collapsed in 1991, Vasili Mitrokhin, a KGB archivist, fled with a trove of secret information which he handed to British intelligence. Jack Barsky’s name was in Mitrokhin’s papers.

Clued in, the FBI started surveilling him and his family, searching their household trash at the Pennsylvania house and eventually buying the home next door. They moved in a male and female agent to watch him — a twist remarkably similar to the plot of the TV show “The Americans.”

Barsky was brought down by his own attempts to save his now-foundering marriage.

“I need to tell you something,” he told Penelope in their wiretapped home. He admitted he had been a KGB agent, and that he broke ties with Moscow to protect their family. “I could have been captured or killed. Does that mean anything to you?” he pleaded.

In May 1997, Barsky was pulled over on Route 80 by a Pennsylvania State Trooper. When he stepped out of his car at the officer’s request, a second man approached. “Special Agent Reilly, FBI,” the man said. “We would like to talk with you.”

Reilly and another agent drove Barsky to a hotel where they’d set up an interrogation center. “Jack, this does not have to be the worst day of your life,” Reilly said. Barsky didn’t need to be prompted to cooperate. Two hours later, the agents let him go home, with the caveat that he was still under surveillance.

That weekend was Barsky’s — Dittrich’s — real 48th birthday. “I wondered where I would spend my 50th,” he writes.

Over the following months, Barsky told the FBI everything he could. He only knew the first names of his KGB comrades — and he wasn’t sure those names were real. The only contact he remembered for sure was an address in Berlin where he sent coded letters. “The FBI already had that one,” Barsky said.

The government decided not to charge him, and the FBI even helped legalize the identities of Barsky and his wife. He and Joe Reilly, the FBI agent who brought him in, became true friends and golf buddies.

A free man — and officially now an American citizen — he continued his career in information technology, later developing software for the New York Independent System Operator, which manages the state’s power grid.

Mitrokhin’s records led Barsky to believe he was part of a third wave of illegals the KGB hoped to set up in the US between the end of World War II and the late 1980s.

Barsky said he was probably one of six illegals planned for that third group. “How many of those six residencies were actually established is not known,” he said.

“According to Mitrokhin, all three waves failed miserably. I’m not surprised based on circumstances. This had become a nearly impossible task to do, to establish yourself as an illegal and then actually get to a point where you are in a position to either obtain secrets from somebody else, or steal them.”

Barsky figures he’s now safe from any Russian assassination attempts — a fate that has allegedly befallen enemies of Russian President Vladimir Putin. “It’s not worth it; there’s no point to it,” Barsky said. “Anybody who might have had a personal vendetta against me, they are either all dead or too old to care.”

All in all, Barsky, 67, is happy. Raised an atheist, he now has a strong Christian faith. He lives in Georgia with his third wife and their young daughter. Over the years, he’s rebuilt his relationships with his German sons. On a 2015 trip to Germany, he got a picture of himself with all four of his adult children. He’s still good friends with Joe Reilly, who is retired from the FBI.

“The United States,” he said, “is still the greatest country in the world.”