Alexander “Alec” Wilson liked getting married. He did it often. The British spy and best-selling novelist married his first wife, Gladys, in 1916. He wed Dorothy Wick, an actress, sometime around 1928. He exchanged vows with Alison McKelvie while she was his secretary at the British Secret Intelligence Service in the early 1940s. Before he died, in 1963, Alec wed nurse Elizabeth Hill.

There was just one hitch: Wilson was married to all four at the same time.

His outrageous story of bigamy and deception is delicately detailed in “Mrs. Wilson,” a three-part PBS series debuting Sunday night on “Masterpiece.” The title is apt because, well, there were so many Mrs. Wilsons. Only the first marriage, to Gladys, was legal: His unions with the next three — including Alison, grandmother of “The Affair” star Ruth Wilson — were not.

“He was a very intriguing character,” says Anna Symon, who sat down with 15 to 20 of Wilson’s descendants before writing the drama, which stars Ruth Wilson, who plays her own grandmother. “He appeared to have everything going for him. And women fell at his feet.”

In an interview with Britain’s Radio Times, Ruth revealed how her grandfather pulled it off. “He changed his middle names often so that [his name] didn’t have a record of a previous marriage.” Alexander Joseph Patrick Wilson became Alexander Gordon Chesney Wilson, and nobody figured out that he was already married.

Symon’s telling begins at the end, when Alison rushes home from work to fix lunch for Alec (Iain Glen, “Game of Thrones”). After setting the table, she calls to him — only to find him dead of a heart attack in front of his typewriter. When a strange woman knocks on her door and identifies herself as Mrs. Wilson, the first chapter of her husband’s secret life unfolds.

Yet Alison, who died in 2005, didn’t know there was a third Mrs. Wilson. Alec left still-wife Gladys and their two sons in England when he went to India in 1925 to teach. “That’s where he met Dorothy Wick, a very beautiful actress,” Symon tells The Post. “She married him in good faith.”

The India years of Alec’s life remain mysterious, especially as the British government will not let his descendants read his MI6 files, claiming his case is “security-sensitive,” Symon says.

“The bit in India is where it becomes murky,” she says. “Who was deluding whom about what went on? I’ve told what I think is the [reasonable] version of the truth. Dorothy [who died in 1965, two years after Alec] isn’t alive to tell us what happened.”

With Gladys and the kids in Southampton, Alec, Dorothy and their son Michael, born in 1933, moved back to London. Alec shuttled between both wives for extended periods of time, but disappeared from Michael’s life when the boy was 7. Dorothy told him his father died in the Battle of El Alamein, in Egypt, in 1942.

In London, Alec worked at the MI6 office, where his ability to speak eight languages was in demand. “He was listening to the embassies in London to all the different countries,” Symon says. “He was listening in for strategies.”

His strategy for meeting women was undergoing some change as well. When Alison became Alec’s secretary in 1940, he shaved several years off his age. Alison, Symon says, “wanted to do her bit for the war effort. She came from an aristocratic family in the countryside where women wouldn’t have worked.” When she met Alec, she was “looking for someone to fall in love with. She met this guy who was a famous writer, highly regarded. She fell at his feet.”

Which begs the question: Why did Alec keep getting married and having more children? “I think it came down to his Catholic faith,” Symon says. “He was an amazingly generous, kind, thoughtful man. In some sort of twisted way, he thought he was doing right by these women by marrying them.”

The multiple marriages and children — seven in all — took their toll. Though Alec’s books sold well, he was always broke, and he and Alison and their two sons moved 17 times in 10 years because they couldn’t pay the rent.

Alison Wilson never knew about the fourth Mrs. Wilson, Elizabeth, whom Alec met when he was a hospital porter in the 1950s. After Elizabeth became pregnant, they wed, and their son arrived in 1955.

“I don’t think he was a cad,” Symon says. “Because he’s been telling lies for a living by working for the intelligence service, he became confused and ended up in situations beyond his control. The women wanted to rescue him.”

Eventually, Alec Wilson’s children and grandchildren found each other. “They’ve got this immense fondness and respect for Alec,” Symon says. “They don’t judge him for what he did. They’re strong, surviving people.”