MJ Hegar, an Air Force pilot shot down by the Taliban in Afghanistan, was a political unknown until she opened fire with 2018’s most effective political weapon: the viral online video.

Hegar’s 3½ -minute biographical ad, called “Doors,” has been viewed online by nearly 5 million people. It features the door from the chopper whose crash she survived and refers to the glass door she says her mother was thrown through by her abusive father. Inspired by Hegar’s story, donations have poured into the Texas Democrat’s campaign to unseat Rep. John Carter, a Republican who has been in Congress since 2003.

In New York’s Democratic primary on June 26, 28-year-old activist Alexandria Ocasio-Cortez knocked off incumbent Rep. Joseph Crowley, a 20-year veteran and power broker in Congress, partly on the strength of her online video.

In it, Ocasio-Cortez, a community activist who tended bar and waited tables until recently, introduces herself to her heavily Hispanic district in the Bronx and Queens. It would have cost a fortune to air the ad on TV in the New York market, but through Facebook, YouTube and Twitter she inexpensively explained her working-class Puerto Rican roots and her demands for “Medicare for all” and free public college tuition.

Millions of people have viewed her ad. Ocasio-Cortez won Tuesday’s election by 4,000 votes. After the November election, she will probably be the youngest member of Congress.

In a year when a record number of women are running for political office — often in their first campaigns — many are overcoming disadvantages in cash and name recognition with well-produced online videos that tell their personal stories.

In some cases, the videos are turning women who were until recently not even widely known in their own neighborhoods into national sensations.

“It’s a new way for an underdog to raise their profile nationally and rise up above the crowd,” said Mark Putnam, whose firm has created several hit political ads, including Hegar’s “Doors.” These ads also have helped male candidates, but Putnam said they seem to be particularly valuable to women because so many are little-known and have compelling life stories.

“The ones that are getting the most attention are for women,” he said. Many candidates are trying them, but not all campaign videos break through.

“I think everybody is trying to get a leg up in a very crowded marketplace,” Putnam said. “Everyone is trying to capture magic in a bottle with a viral video.”

In Kentucky, Amy McGrath, a former Marine fighter pilot who has never held elected office, overcame a 47-point disadvantage in early polling to win the Democratic primary, defeating the mayor of Lexington. She won without Democratic Party backing but with the help of a biographical ad that has been seen at least 1.8 million times just on YouTube.

These women have won their primaries. Will they be elected in November?

In Montana, Kathleen Williams beat better-funded competitors in a June Democratic primary, a key hurdle in her bid to become the first woman elected to Congress from her state since the 1940s. Her ad, shared widely on social media, showed her as a caregiver for her mother, who suffered from Alzheimer’s disease, and as a state legislator fighting for better health care.

For many candidates, the main purpose of the ads is to raise money.

Successful ads generate buzz, prompting news stories and generating donations — which can be made by supporters near and far via the same website showing the ad.

In her ad, Hegar, a mother of young children, has tattoos visible on her left arm — a small sign of a big change. Women running this year fit no one model, each presenting themselves as ordinary people with varying backgrounds, just like voters. Many are minorities and young. Unlike past years, female candidates are not pictured in their own ads with coifed hair and plain pantsuits.

Kelly Dittmar, a political scientist at Rutgers University’s Center for American Women and Politics, said women used “to neutralize their looks.” But now, Dittmar said, “there is an expanding image of what it is to be a candidate.”

Ocasio-Cortez’s video shows her in her small apartment, switching from comfortable to work shoes on a subway platform, underscoring her words: “Women like me are not supposed to run for office.”

Her victory over Crowley, which stunned even her, was greatly aided by her far bigger presence and reach on social media.

“She went from relative social-media obscurity to being talked about overnight,” said Todd Grossman, the Americas chief executive of the social-media analytics firm Talkwalker. He said the way she used her online video and Facebook and Twitter accelerated her candidacy.

The day Ocasio-Cortez posted her ad, she gained 6,700 new Twitter followers, according to Talkwalker.

Ocasio-Cortez is favored in November, given her district’s safe Democratic status. Hegar, the former Air Force rescue pilot, still has a tough battle ahead as she tries to unseat Carter, 76. For starters, she is a Democrat running in a conservative Texas district, where her message about the political system “shutting doors” on people like her may have limited effectiveness.

But her viral video gave her campaign a jump-start and spread word of her candidacy well beyond her district’s boundaries north of Austin.

One fan praising her video from a distance was the creator of the hit Broadway musical “Hamilton,” Lin-Manuel Miranda.

After seeing it, he tweeted to his 2.4 million followers: “MJ, you made the best political ad anyone has ever seen.”