ROSWELL, Ga. — Jon Ossoff, a Democrat making his first bid for elective office, was hovering at just under 50 percent of the vote, according to The Associated Press, in a special election Tuesday for a heavily conservative House district that has not been filled by a Democrat since the Jimmy Carter administration.

In a vote slowed by a data error in Fulton County, Mr. Ossoff had a wide lead in a field of 18 candidates, with Karen Handel, the top Republican vote getter, in second place with just under 20 percent of the vote as of 12:30 a.m. Wednesday, according to The A.P. If that margin holds, the two will face off in a June runoff in a race that has been seen as a referendum on President Trump’s performance in office.

A documentary filmmaker and former congressional staff member, Mr. Ossoff, 30, had hoped to avert a runoff in the district, a Republican-dominated section of Atlanta suburbs that had been represented by Tom Price, who is now President Trump’s health and human services secretary. But despite his financial advantage — Mr. Ossoff had raised $8.3 million, more than quadruple that of the next closest candidate — and a highly energized liberal base, a majority seemed just out of reach.

The Run-Up

The podcast that makes sense of the most delirious stretch of the 2016 campaign.

Mr. Ossoff appeared at his party just before midnight and told then that they may not know the outcome of the vote “for some time.”

“But let me tell you this — there is no doubt that this is already a victory for the ages,” he said. “That no matter what the outcome is tonight, whether we take it all or whether we fight on, we have defied the odds. We have shattered expectations. We are changing the world.”

Mr. Ossoff’s strong showing will ensure that national Democrats continue to compete here and will increase pressure on the party to contest a special House election next month in Montana that it has so far ignored. Combined with Democrats’ better-than-expected performance in a special House election in Kansas last week, Tuesday’s result will be an immediate boon to Democratic groups, lifting their fund-raising and bolstering candidate recruitment efforts, while sobering Republicans who are assessing whether to run in Mr. Trump’s first midterm election. Already, Republican candidates and outside groups have had to spend over $7 million against Democrats in a series of deeply conservative districts.

Interactive Feature | Highlights: Georgia Special Election Here’s how we analyzed Georgia’s special election through about 11 p.m. Eastern on Tuesday, which the Democrat Jon Ossoff cast as a referendum on President Trump.

It is unclear whether Mr. Ossoff can sustain the success he enjoyed on Tuesday, in an 18-person field, when he faces Ms. Handel in a head-to-head race on June 20. Ms. Handel, who received TK percent of the vote Tuesday, is a former Georgia secretary of state and is viewed as an establishment-friendly Republican. While she has struggled in her two previous campaigns, losing primaries for governor and senator, she will receive the full support of a party that dominates Georgia politics, as well as nearly unlimited resources from Washington Republicans, in the runoff.

Ms. Handel, 55, has portrayed herself as a Trump supporter, though she was less fervent in her support for him than the other Republican candidates in the race, who adopted Mr. Trump’s catchphrases and style in an attempt to stand out.

The intense Republican competition and liberal enthusiasm lifted Democratic hopes that they could snatch a surprise victory.

“We are certainly going for an outright win here today,” Mr. Ossoff told CNN on Tuesday before the polls closed.

Much as they did in last week’s race in Kansas, Democrats initially got their hopes up after promising early-vote returns were posted soon after polls closed. But as the Election Day results trickled in, it became clear that those early and absentee ballots, reflecting their fired-up base, would not be sufficient to match the Republicans’ structural advantage in the district.

On Tuesday night, hundreds of Ossoff supporters crammed into a ballroom at a Crowne Plaza hotel. Cries of delight erupted as early returns flashed on big television screens. But many attendees were cautiously optimistic, with an emphasis on caution.

Graphic | 2017 Election Calendar and Results: Special Congressional and State Elections This year, there will be five special House elections, four to fill vacancies left by members of the Trump administration.

Janice Owens, 60, a project manager who had been knocking on doors and making calls for Mr. Ossoff, said she and others would not feel the effort was wasted if Mr. Ossoff failed to avert a runoff.

“I don’t think anybody thinks it’s for naught,” she said. “Because we’re not giving up.” If anything, the Ossoff campaign showed how Democrats had been successful, even in this Republican-friendly chunk of suburbia, in converting an enthusiastic but inchoate anti-Trump movement into a real political force.

Ms. Handel took the stage at a lightly attended victory party of her own shortly after 11 to claim her spot in the runoff — and urge Republicans to unify so as to stop Democrats from their effort to “steal a seat.” Ms. Handel, battling a few bouts of feedback from a microphone, invoked the “great legacy” of a district she noted has produced former Speaker Newt Gingrich, Senator Johnny Isakson and Mr. Price. But she made no mention of Mr. Trump. Ms. Handel dismissed her opponent as a “young man” beholden to national liberals and vowed to “kick a little Ossoff.”

The contest here effectively represented the first performance review at the ballot box for Mr. Trump and the Republican Congress among the sort of upscale voters who were left without a political home last fall. Mr. Price’s former district is the most highly educated Republican-controlled district in the country. And while the president won here in Atlanta’s booming northern suburbs, he did so by just a single point four years after Mitt Romney romped to a 23-point victory.

For all of the attention lavished on the working class — Rust Belt voters who flocked to Mr. Trump’s campaign — voters who have flourished in the 21st-century economy will prove more crucial when it comes to the fight for control of Congress next year. If Democrats are to have a chance at recapturing the House, they will have to win over the dominant constituency here: suburbanites who only grudgingly cast a presidential ballot in November and have no deep affinity for either Mr. Trump or the Democrats.

None of the major Republican contenders pointedly distanced themselves from the president — they did not dare anger the partisans most likely to vote in a spring special election — but most of them did not make him central to their appeals, either.

Interactive Feature | Get the Morning Briefing by Email What you need to know to start your day, delivered to your inbox Monday through Friday.

With Republican Party officials worried that Democratic enthusiasm might be enough for Mr. Ossoff to get more than 50 percent of the vote and win the seat outright, though, Mr. Trump eventually did weigh in on the contest. He recorded a robocall delivered Monday to Republican voters in the district, warning that Mr. Ossoff would “raise your taxes, destroy your health care and flood our country with illegal immigrants.” And he posted on Twitter a series of messages similarly criticizing Mr. Ossoff while prodding Republicans to “force runoff.”

Mr. Ossoff walked a careful line when it came to Mr. Trump. He opened his bid with donor-tailored appeals to “Make Trump Furious,” and continued similar targeted advertising throughout his campaign. But he also sought to cast himself as a consensus-oriented moderate focused on the district, dismissing Mr. Trump’s late intervention as so much noise from Washington.

Sensing an opportunity to deliver an early blow to Mr. Trump, and nudged ahead by an animated base hungry to register its fury, Democrats aggressively competed to win outright on Tuesday and avert a more directly partisan runoff. In addition to Mr. Ossoff’s astounding $8.3 million haul through the end of March, the House Democratic campaign arm poured money and staff into the district.

Republicans were as fractured as Democrats were unified, with political veterans such as Ms. Handel on the ballot as well as newcomers who saw an opportunity at a moment when the party seemed to be in flux.

The Republican field was divided over the failed bill to repeal the Affordable Care Act, but it treated the issue delicately in what amounted to a concession that what was once the safest stance in a Republican primary — demanding full repeal of President Barack Obama’s health care law — was not so clear-cut any longer.

In an illustration of how nationalized the race became, 95 percent of Mr. Ossoff’s fund-raising haul was from out of state, and nearly as much was from outside the district, where the candidate himself does not reside (though he grew up there).

Republicans blistered him on this score and much else, a kitchen-sink campaign that totaled $5 million yet also stirred muttering within the party about why there had not been a more coherent approach to a district they knew would be competitive, given Mr. Trump’s weakness here. But the unrelenting Republican assault eventually paid off, raising Mr. Ossoff’s negative ratings and nudging conservative voters to show up for an unusual spring election.