U.S. Senator-elect Tim Kaine (D-Va.) pumps his fists as he celebrates his senate race victory on stage with supporters Nov. 6 in Richmond, Va. (JONATHAN ERNST/REUTERS)

Democrats retained their majority in the U.S. Senate on Tuesday, leaving Congress divided along the lines that have led to gridlock for the past two years on some of the nation’s most pressing issues.

A combination of misfortune and mistakes left Republicans unable to seize control for the second straight election in which they were early favorites to make historic gains.

In a key race between Virginia political heavyweights, former governor Timothy M. Kaine (D) defeated former senator George Allen (R) .

Kaine won big in Fairfax County but also appeared likely to carry exurban Loudoun and Prince William counties. Such a result would mimic the Northern Virginia coalition that carried Kaine to the governor’s mansion in 2005. His victory ended an attempt at political redemption by Allen, a onetime possible presidential contender who lost his Senate seat to James Webb (D) in 2006. Webb decided not to run for reelection this year.

The Democrats flipped Republican Senate seats as the GOP saw sure-bet Indiana slip away. Rep. Joe Donnelly defeated conservative state treasurer Richard Mourdock, who sank after saying he believed that pregnancies resulting from rape reflect the will of God.

In Massachusetts, liberal hero Elizabeth Warren gave Democrats an emotional win by snatching back from Republican Scott Brown the Senate seat once held by Edward M. Kennedy. Brown had won the seat in a 2010 special election called after Kennedy, who served nearly 47 years, died in 2009.

After a series of hard-fought and sometimes nasty battles in Senate races that spanned the country, little changed in the chamber.

Democrats were likely to expand on their current 53-to-47-seat edge. But they did not appear to be in a position to gain the seats necessary to win a filibuster-proof 60-seat majority, meaning a continuation of the gridlock that has been a hallmark of the modern Senate.

Still, a bare majority for Democrats offers them the chance to control the chamber’s agenda and committee structure. With that edge comes new leverage in negotiations over the nation’s most difficult problems, including fiscal issues that must be addressed even before the next Senate takes office in January.

With the GOP retaining control of the House of Representatives, Democrats needed to hold the Senate as a legislative ally to a reelected President Obama.

Until recently, Democrats were thought to be in danger of losing the Senate, given that only 10 Republican seats were up for grabs this year, while 23 Democratic seats were in play, including in a number of Republican-leaning states.

The GOP missteps of the 2012 race are likely to lead to a party reckoning before 2014, when Democrats will once again be defending more seats than Republicans.

Republican troubles began when moderate Sen. Olympia J. Snowe announced her retirement, citing the Senate’s bitter partisanship. That paved the way for the loss of the GOP seat to independent former Maine governor Angus King. King has not said with which party he will caucus, but he is widely expected to side with Democrats.

Then establishment Republicans lost control of state nominating contests, as they did in 2010, and watched as the fate of the Senate was handed to candidates ill-suited to general elections.

Two Republicans who won their party’s nomination with an appeal to the party’s right uttered cringe-worthy statements about abortion and rape, putting likely GOP wins in doubt.

In Missouri, Rep. Todd Akin was abandoned by national Republicans, including Mitt Romney, after saying that pregnancies rarely result from “legitimate rape.”

He apologized but was haunted by the remark and lost Tuesday to Democratic Sen. Claire McCaskill, who was once thought to be one of the nation’s most endangered incumbents.

The Democratic win in Indiana was especially painful to Republicans because Mourdock got on the ballot only after defeating 36-year incumbent Sen. Richard G. Lugar in a bitter primary fight.

Republicans were also plagued with difficulties recruiting top-notch candidates, leaving lesser-known or flawed nominees battling in some of the nation’s biggest and most important electoral contests.

In Florida, Democratic Sen. Bill Nelson defeated Rep. Connie Mack, even as Romney and Obama were locked in a tight race late into the night in the state.

The same was true in all-important Ohio, where Sen. Sherrod Brown (D) defeated state treasurer Josh Mandel.

Some of the nation’s marquee races were in states where the presidential election was not in doubt.

They included Massachusetts, home to perhaps the country’s most closely watched Senate campaign. There, Brown campaigned as an independent-minded everyman against consumer crusader Warren, who argued that Obama needed a Democratic ally in the Senate.

The contest held deep emotional resonance for both sides. Democrats longed to regain a seat that had been lost after Kennedy’s death in a race that was dominated by the national debate over health-care reform.

In Connecticut, former wrestling executive Linda McMahon (R) also ran as an independent voice, but lost to Rep. Chris Murphy despite spending millions of her own money to convince voters supporting Obama that they could also vote for her.

Romney easily won the presidential race in Montana and North Dakota — but the deeply conservative states were home to two of the nation’s most hotly contested Senate races. In Montana, Sen. Jon Tester (D) staved off Rep. Denny Rehberg. And in North Dakota, Rep. Rick Berg (R) faced a surprisingly tough battle from former state attorney general Heidi Heitkamp to replace Sen. Kent Conrad (D), who will retire in January. That race remained too close to call as of late Wednesday morning, although Heitkamp had a slight lead, according to the Associated Press.

Republicans prevailed in one state now held by Democrats — Nebraska. In that race, state Sen. Deb Fischer (R) defeated former senator Bob Kerrey (D) in a race to replace retiring Sen. Ben Nelson (D).

But the presidential battlegrounds also saw tight races. In Wisconsin, Rep. Tammy Baldwin (D) defeated former Republican governor Tommy Thompson (R) to become the nation’s first openly gay senator.

In Pennsylvania, Sen. Robert P. Casey Jr. (D), who had long been thought likely to sweep to easy reelection, beat coal executive Tom Smith, who spent more than $17 million of his own money on the race.

And in Nevada, Sen. Dean Heller (R) narrowly defeated his challenger, Rep. Shelley Berkley, even as she tied herself to Obama and leaned heavily on a turnout machine headed by Senate Majority Leader Harry M. Reid.

Julie Tate contributed to this report.