But after the previous representative, Trent Franks, resigned following revelations he had offered $5 million to an aide in exchange for carrying his child, Arizona Democrats rallied to Ms. Tipirneni. She outraised Ms. Lesko in what was the first high-profile congressional election since 2016 between two women.
National Democrats, however, stayed away from the race, deducing that a district that has sent only Republicans to Congress for four decades was out of reach. And any hopes Ms. Tipirneni had to win outside support may have faded this month when a local TV station reported that she had not practiced medicine since 2007 and had settled a malpractice lawsuit with a woman who blamed her for contracting tetanus.
In contrast, the Republican National Committee, the National Republican Congressional Committee and the Congressional Leadership Fund, the primary House Republican super PAC, each poured hundreds of thousands of dollars into the race. The investment proved critical in what became an unexpectedly close race.
“It’s a warning shot,” Senator Jeff Flake, Republican of Arizona, said of the results. “Anything below a 10-point margin is not good news.”
Ms. Lesko, 59, ran as a dependable supporter of Mr. Trump and assailed Ms. Tipirneni for not backing White House priorities like the construction of a wall on the Mexican border. With help from the battery of outside Republican organizations, Ms. Lesko sought to polarize the district along traditional partisan lines, branding Ms. Tipirneni as a liberal and a puppet of Representative Nancy Pelosi, the House Democratic leader.
Rather than wait for the contest to tighten, the groups helped Ms. Lesko build an early advantage in a race in which the vast majority of voters cast their ballots early. Registered Republicans far outnumbered Democrats in the early voting period, and the median age was 67 among those voting before Election Day, an indication of a heavily conservative electorate.
Ms. Tipirneni, 50, found energetic support among some women in the district who were uneasy about Mr. Trump and had been roused to get active in politics. As Representative Conor Lamb of Pennsylvania did in a special election last month, she offered herself as a moderate who would not support Ms. Pelosi for House speaker.
But unlike Mr. Lamb’s Pittsburgh-area seat — which includes an array of vote-rich, upscale suburbs — the Arizona district is full of AARP-eligible snowbirds, reliably Republican Mormons and military families who work at nearby Luke Air Force Base. And this race was a head-to-head contest — there was no Libertarian on the ballot, as in Pennsylvania, who could have allowed Ms. Tipirneni to eke out a win had it proved closer.
This was not a district that was on either party’s list of seats that will determine control of the House. But the steps conservatives took to secure victory for a former officeholder illustrate just how much the anti-Trump energy on the left is putting Republicans on the defensive across the country.