Appearing with Giffords at a Tucson hotel after his victory Tuesday night, Barber told supporters, "Life takes unexpected turns and here we are, thanks to you." Giffords hugged him and kissed his forehead.
Barber defeated Republican Jesse Kelly, who narrowly lost to Giffords in 2010 in a competitive district that Republicans have won in the last two presidential elections. Giffords has made few public appearances since resigning in January to focus on her recovery, but she dashed back to Tucson during the campaign's final days to help her former district director.
Democratic officials were quick to argue that the victory sets the stage for them to win back control of the House.
"This campaign previewed the message fight that will play out across the country in November: Democrats committed to protecting the middle class, Social Security and Medicare versus misleading Republican attacks on Obamacare and national Democrats," said Rep. Steve Israel, D-N.Y., chairman of the Democratic Congressional Campaign Committee.
But Rep. Pete Sessions, R-Texas, the chairman of the National Republican Congressional Committee, said special elections are unique and the Arizona race was particularly so because of what had happened to Giffords. He predicted that Barber would not fare as well in the fall with President Barack Obama leading the ticket.
"No one wanted this election to happen or to see Gabrielle Giffords step down from Congress, but Jesse ran a campaign focused on pro-growth policies that will lead to less government and a strong and vibrant economy," Sessions said.
In his concession speech, Kelly said: "We executed the plan we wanted. The voters of southern Arizona did something different."
Republicans had sought to make the contest a referendum on Obama and his handling of the economy. Democrats played to the senior vote by contending that Kelly would not protect Medicare and Social Security.
With 100 percent of precincts reporting, Barber won about 52 percent of the vote while Kelly had 46 percent.
Both candidates have promised to run for a full term in the fall, setting up a possible November rematch in a redrawn district that is friendlier to Democrats. Republican voters outnumber Democratic voters by about 26,000 under the current map. That edge will narrow to about 2,000 under redistricting.
Elsewhere Tuesday, Virginia, North Dakota, Nevada, Maine, Arkansas and South Carolina held primary elections.
In Virginia, George Allen, a former governor and senator, brushed aside three rivals in the Republican Senate primary. Allen's victory set up a November clash with another former Virginia governor, Democrat Tim Kaine, in a campaign closely tied to the presidential race in a state both parties consider vital for victory.
In North Dakota, Rep. Rick Berg defeated businessman Duane Sand in the state's Republican Senate primary. Berg faces Democrat Heidi Heitkamp in the November race to replace retiring Sen. Kent Conrad. The election is expected to play a critical role in determining which party controls the Senate.
Voters also decided to let the University of North Dakota scrap its controversial nickname, the Fighting Sioux. The NCAA had deemed the name hostile and abusive, and placed the university under postseason sanctions. The state's Board of Education is expected to retire the moniker and American Indian head logo.
In Nevada, Republican Sen. Dean Heller and Democratic Rep. Shelley Berkley easily defeated a slate of political unknowns in their respective primaries. Their fall race will be one of the most competitive in the country.
In Maine, state Sen. Cynthia Dill won the Democratic primary in the race to succeed Republican Sen. Olympia Snowe. Maine Secretary of State Charles Summers won the GOP nomination.
The front-runner, former two-term Gov. Angus King, wasn't on the ballot because he's running as an independent.
No statewide races were part of the Arkansas and South Carolina primaries.
Of all the races Tuesday, the Arizona House race was the most closely watched, partly because of Giffords' absorbing story and partly because holding onto the seat is important for Democrats if they want to regain control of the House.
The party needs big gains in November to grab the majority from Republicans, who now hold a 240-192 advantage with three vacancies, including Giffords' seat.
Republicans, riding high after a decisive victory in Wisconsin's gubernatorial recall election last week, set their sights on Arizona. A victory would have given party leaders a chance to claim momentum five months before November and fine-tune their plan to link Democratic candidates to Obama, the incumbent at the top of the ticket.
Outside groups spent more than $2 million on the race. Barber, 66, had a sizable fundraising lead in late May, but spending from conservative groups helped reduce the Democratic financial edge.
The Arizona 8th is a rare district that is competitive practically every election. Giffords defeated Kelly by about 4,000 votes in 2010, when the election focused on immigration and when tea partyers rallied to the tough-talking former Marine. Now, the economy and jobs are voters' top concerns.
Democratic officials were thrilled that Barber won a district that President George W. Bush carried with 54 percent of the vote in 2004 and that John McCain carried with 53 percent of the vote when he ran against Obama.
Kelly, 30, spent the campaign arguing that Barber and Obama are out of touch with people in the district. He called for lower taxes and more energy production as ways to improve the economy. And he said he would roll back federal regulations and environmental protections in an effort to boost oil and gas drilling.
Freking reported from Washington. Associated Press writers Carson Walker contributed from Tucson and Dave Kolpack contributed from Fargo.