Petraeus, the architect of the troop surge escalation strategy credited by the Bush administration with improving security in Iraq, will be promoted to run US Central Command.
The vote on the Petraeus nomination was 95-2 in the 100-member Senate.
The chamber also voted 96-1 to confirm Lieutenant General Raymond Odierno to replace Petraeus as the senior US officer in Iraq.
Petraeus's promotion puts him in charge of the US military's biggest challenges — Iraq, an expanding military effort in Afghanistan, an Al-Qaeda revival in Pakistan, and challenges from Iran on various fronts.
He replaces Admiral William Fallon, who abruptly stepped down in March after saying that media reports describing him as at odds with the White House over how to deal with Iran had become "a distraction."
Petraeus will make a recommendation in mid-September, before he leaves his current post, on whether the drawdown of US forces can continue after the last surge brigade leaves Iraq in July.
In March, Defense Secretary Robert Gates said the long lead time and Petraeus's replacement with Odierno were intended to avoid disrupting the momentum gained from the surge and to assure a smooth transition.
Pentagon press secretary Geoff Morrell welcomed the confirmation.
"Individually they are ideally suited for these challenging jobs and collectively they make a great team," he said.
"Working together they have made dramatic security gains in Iraq and hopefully they will be able to build upon that success to create a more stable and secure Middle East."
Hoping to expand his success from the troop surge strategy he spearheaded since early last year, Petraeus last month issued new counter-insurgency guidelines that underscore the importance of winning citizens' hearts and minds in the war in Iraq.
The 23-point document demands that US soldiers engage with and respect citizens while relentlessly pursuing Al-Qaeda and other extremist groups blamed for destabilizing the nation of 25 million people.
"The Iraqi people are the decisive terrain," Petraeus said in a June 21 statement, adding that US troops must "secure and serve the population," "live among the people," and "employ money as a weapon system."
The success of the US mission in Iraq, which has teetered on the brink of collapse, depended on working with the Iraqi people to provide security and restore basic services and rebuild local economies, Petraeus said.
The US military is currently withdrawing five combat brigades sent into Iraq early last year — the so-called "surge" force — to be completed by July. That would bring troop levels down from about 158,000 to 140,000.