Republican candidate for Maryland governor Larry Hogan campaigns at the Potomac Days parade in Potomac, Md., on Oct. 25, 2014. (Kate Patterson/for The Washington Post)

With less than six weeks to go before the election, Larry Hogan’s political strategists realized they had a crisis on their hands.

The Democrats were pounding him hard on social issues, outspending Hogan on the air by more than 3-1 with a barrage of ads that suggested he would ban abortion and birth control.

So on Sept. 24, Hogan’s ad-making team showed up at his house in Annapolis and shot three versions of a new television spot. One had the candidate deny the charges directly into the camera. Another was more relaxed and conversational, showing him speaking to an interviewer. The third had his 34-year-old daughter, Jaymi Sterling, vouching for her dad.

Working in the editing room until 3 a.m. the next morning, they turned Sterling into gold.

How the Hogan campaign managed to get up off the mat is an object lesson for Republicans as they grapple with their continuing disadvantage among women voters. And it helps explain why — in this midterm election, at least — the “gender gap” did not turn out to be the potent force that Democrats had hoped it would be in Maryland and across the nation.

A record number of women will be sworn into the 114th Congress — but that still doesn't shatter the glass ceiling. Here's a look at some firsts for women in the upcoming Congress, by the numbers. (Julie Percha/The Washington Post)

In the deeply blue state of Maryland, the GOP gubernatorial nominee knew he could not win unless he could convince significant numbers of Democratic and independent women to cross party lines and vote for him on pocketbook concerns.

But with the Democratic attacks, “There was a cacophony in the D.C. market, right out of the ‘war on women’ playbook,” recalled Ashley O’Connor, one of Hogan’s campaign consultants. “If this went unanswered, we were afraid this could turn into a running narrative.”

As they considered the alternative versions of the ad, they realized they had found the perfect emissary — one who could speak not just to his positions, but also to his values.

“Let me tell you about my dad, Larry Hogan. He married my mom and became the father of three independent, strong young women,” said the candidate’s daughter, who is Korean American and has the courtroom polish of a prosecutor, which she happens to be.

“These ads attacking him as anti-women are just wrong,” Sterling added. “He’s the only candidate who favors over-the-counter birth control, covered by insurance. He’s committed to not changing current Maryland law on choice. Dad encouraged my sisters and me every step of the way. He loves this state — almost as much as he loves us.”

The campaign’s final ads featured a series of women from around the state talking about economic concerns — in other words, emphasizing the issues that Hogan considered his biggest advantage, but using women to make the closing arguments.

One week before election day, Hogan’s internal polls showed him five points ahead of Lt. Gov. Anthony G. Brown, the Democratic nominee — almost the exact margin by which he ultimately pulled off his surprise victory.

And, remarkably for a Republican, Hogan was running a mere two percentage points behind among female voters in his campaign’s private polls. (No exit polls were conducted in Maryland, so it is impossible to know how close that was to the final result.)

Republicans traditionally have had a problem appealing to women. The results of Tuesday’s midterm elections show that they still are at a disadvantage. But although the GOP lost the female vote nationally by 11 percentage points in 2012, the party ran only 4 percentage points behind Democrats this year.

It helped that none of their candidates committed the kind of gaffes that stoked the “war on women” narrative and put them on the defensive in 2012.

There was no one saying that pregnancy doesn’t happen where there has been a “legitimate rape,” as Missouri Senate candidate Todd Akin infamously said. Or suggesting that if it does, it was “something God intended,” as the GOP’s Indiana nominee Richard Mourdock did.

“In 2012, the errors of individual candidates were something the Republican party had to own,” said O’Connor, who worked on the presidential campaign of GOP presidential nominee Mitt Romney that year.

It also may be that the traditional Democratic attacks are losing their effectiveness or that Republicans are doing a better job anticipating them.

Nowhere had reproductive issues loomed larger than in the Colorado Senate race, where incumbent Democrat Mark Udall put such emphasis on them that he was dubbed “Mark Uterus.”

Udall was re-running a strategy many credited with saving the seat of Colorado’s junior senator, Michael F. Bennet, in 2010 — another year when the political tide was running against the Democrats.

But this time the Republican candidate, Rep. Cory Gardner, shifted early and renounced his previous support for a state “personhood” measure. Gardner said he had not realized that establishing that civil rights begin at conception might result in a ban on certain types of contraception.

Gardner — like Hogan and a number of other Republican candidates across the country — also came out in favor of selling birth control over the counter. He joked that when Udall ran an ad accusing him of trying to ban contraception, “my wife looked at me and smiled and said, ‘Didn’t you used to pick up my prescription?’ ”

Election-day exit polls showed that Udall still won the female vote — but by a margin of eight points, which was less than half the 17-point advantage that Bennet had in 2010. It was not enough to save Udall, who lost to Gardner by two percentage points.

Udall was not the only candidate to overestimate the extent to which reproductive issues would drive women to the polls for Democrats. In Virginia, Democratic congressional candidate John W. Foust ran an ad in which a woman sat in a darkened room and reminded voters that Foust’s Republican opponent Barbara Comstock had voted in the state legislature for a controversial measure that would have required women to undergo transvaginal ultrasounds before they could get abortions.

“That’s all I need to know,” the woman in the ad said.

Apparently that was not an overriding concern for other women. Comstock beat Foust by 16 points.

One problem for Democrats this year was the fact that so many unmarried women — one of the party’s most loyal constituencies — decided not to vote.

“Clearly, for unmarried women, there was a disconnect between what they were looking to hear and what they were hearing. They wanted a strong economic message from these candidates that clearly stated they knew what these women are going through and what it is like to walk in their shoes,” said Page Gardner, president of the Voter Research Center, an organization that aims to encourage more voting by single women and other groups that tend to sit out elections.

Democratic pollster Celinda Lake agreed. While proposals such as raising the minimum wage and paid leave were popular with women, she said, “the Democrats need to expand the rifle-shot issues to an overall economic message.”

Many of the places where Democrats had their greatest advantage with women, Lake said, were those states where women were on the ballot, such as in Senate races in Georgia, North Carolina and New Hampshire. However, they lost all but New Hampshire, which means the Republicans’ edge with men was even greater.

Senior Democratic officials said privately that the GOP candidate they most underrated was Sen.-elect Joni Ernst, the first woman Iowa voted to send to Congress.

Ernst can thank male voters for her victory; she won them by 16 points. But Ernst managed to break even with women voters — which, for a Republican, ranks as an accomplishment.