Sarah Jessica Parker’s new baby saved her marriage to Matthew Broderick.

That’s the secret behind the arrival of little James Wilke Broderick, whose birth on October 28 in New York City made headlines across the country.

“Just a year and a half ago, friends of Sarah and Matthew thought their marriage was heading toward disaster,” said a close source. “With Sarah’s commitment to ‘Sex and the City,’ and Matthew appearing nearly every night on Broadway in ‘The Producers,’ they weren’t spending time together.

“Matthew was partying at Manhattan nightspots like Suite 16 and Luxia with his gorgeous blonde co-star, Cady Huffman. And Sarah was spending time with her former co-star, John Corbett.

“After intense arguments over the future of their marriage, Sarah decided there was only one way to firm up her union with Matthew — and that was getting pregnant.”

In our June 19, 2001, issue, The ENQUIRER reported on tormented Sarah’s misdirected jealousy of married Cady. But her long working hours on “Sex and the City” made Sarah’s solution — having a baby — impossible at the time, and her plan to save her marriage was frustrated.

That frustration showed up at work, a source from the set of her HBO series told The ENQUIRER — Sarah seemed depressed, and even cried on the set.

“Once, she took a break in filming when she saw a mom pushing a baby stroller down the street,” said the set insider. “Sarah just walked away and burst into tears. You could tell she was not happy in her life.”

It took the terror attacks of September 11 to bring the couple’s fading marriage back to life, The ENQUIRER learned.

“They realized how much they meant to one another,” the close source said. “From that point forward, they put 100 percent effort into the marriage and trying to get pregnant. And when she finally got pregnant, Matthew and Sarah were happier than ever.”

Sarah, 37, announced her pregnancy in April. She suffered a miscarriage scare — reported in The ENQUIRER’s July 9 issue — but she made it through and finally delivered her healthy 6-pound, 8-ounce son.

“Now Sarah is thinking about wrapping up her run on ‘Sex and the City’ and Matthew is mulling his next great role — fatherhood,” said the close source. “They’re in love like they were when they first met and they want to make a strong family together.

“Sarah and Matthew’s baby truly saved their marriage.”