In an election to fill former Rep. Gabrielle Giffords, D-Ariz., congressional seat, Democratic candidate Ron Barber, right, celebrates a victory with Giffords, left, as he gives her a hug prior to speaking to supporters at a post election event, Tuesday, June 12, 2012, in Tucson, Ariz. Gabrielle Giffords' former district director, in a special election for the seat Giffords left in January to focus on her recovery from a gunshot wound to her head during a gunman's shooting spree a year earlier.(AP Photo/Ross D. Franklin, pool) (Ross D. Franklin/AP)

Democrat Ron Barber, a former aide to Gabrielle Giffords who was injured in the shooting that nearly took the Arizona ex-congresswoman’s life, won a special election Tuesday to replace her in the House of Representatives.

Giffords joined victory celebrations Tuesday night in Tucson, where she hugged Barber and kissed him on the forehead.

“Life takes unexpected turns, and here we are, thanks to you,” the Associated Press quoted Barber as telling his supporters.

With 100 percent of precincts reporting, Barber won about 52 percent of the vote while his Republican rival, Jesse Kelly, received 46 percent, according to the AP. Charlie Manolakis, the Green Party candidate, came in a distant third.

The contest was the last congressional special election before November’s general election, leaving both sides to mine the results for clues about what might work in November and who might have momentum on their side.

Barber and Kelly, an Iraq war veteran, were vying for the chance to serve out the final few months of Giffords’s term.

Giffords survived an assassination attempt in January 2011 and resigned her House seat earlier this year to focus on her recovery. She supported Barber and campaigned on his behalf, but she was rarely an issue in the battle for the conservative-leaning southeastern Arizona district.

Instead, the race centered on Barber’s connections to the national Democratic Party and Kelly’s past statements about overhauling the nation’s entitlement programs, including Social Security and Medicare.

The Democratic strategy appeared to be paying dividends, and Republicans were pessimistic heading into Tuesday’s vote that they would emerge victorious.

A poll released Monday from Democratic-leaning automated pollster Public Policy Polling showed Barber with a double-digit lead over Kelly.

Barber’s win was seen as resulting in large part from Democratic efforts to define Kelly early on as being against Medicare and Social Security in the district with the 11th-oldest population in the country. In their ads, Democrats ran footage and quotes of Kelly talking about getting rid of the entitlement programs.

Kelly attempted to distance himself from those past positions, airing an ad featuring his grandfather.

Given the large number of senior citizens in the district and Kelly’s past comments, though, the special election was almost a perfect test case for the Democrats’ strategy, which they used in previous special elections and plan to use in the fall. But the political circumstances were not likely to align so perfectly in most other districts.

Democrats, though, pointed out that basically every GOP incumbent has voted for a Republican budget that would overhaul Medicare and that they can use the issue against any number of Republicans, particularly incumbents, nationwide.

On the GOP side, the messaging was all about linking Barber to his national party, including President Obama and House Minority Leader Nancy Pelosi (D-Calif.), along with Obama’s health-care law. And Barber, much like his boss before him, sought to put some distance between his campaign and the president. Giffords, for example, notably declined to vote for Pelosi for speaker in 2011, after Democrats lost control of the House in the 2010 midterm election.

Giffords played a bit part in the campaign, with Democrats featuring her in a piece of mail and a Democratic super PAC running an ad that showed Kelly criticizing her during their 2010 campaign. She also appeared with Barber at a rally last weekend. But in a district where more than half of voters were likely to vote by mail, many if not most ballots had already been cast.

The race didn’t attract as much attention and spending from outside groups as other recent special elections, despite indications that it would be close. It was held just one week after a high-profile gubernatorial recall election in Wisconsin, meaning that much of the nation’s attention was focused elsewhere until seven days ago.

Conservative groups and the national Republican Party spent about $1.4 million on Kelly’s behalf, while the Democratic Party and allied groups spent about $900,000 for Barber.

In any case, Barber and Kelly could be headed for a rematch in November, when both candidates are likely to run again for a full term in a newly drawn district.

Kelly also could face another rematch in the Republican primary for the November election with retired Air Force Col. Martha McSally, who finished second in the special primary election. The primary for the general election will be held Aug. 28.