Petraeus stepped down after spending one year in charge of more than 140,000 international troops in the country.
Allen will be tasked with overseeing the start of the American troop withdrawal from the country after a decade-long war. He was promoted to a fourth star as he took command.
Allen said the drawdown of some U.S. forces and the transition of some areas to Afghan control this week does not mean an easing of the campaign against the Taliban.
"It is my intention to maintain the momentum of the campaign," Allen said at the handover ceremony in the Afghan capital.
Before taking over from Petraeus, Allen had been serving as the deputy commander at U.S. Central Command in Tampa, Florida. He is best known for his role in the stewardship of the Anbar Awakening - the ultimately successful campaign by U.S. forces in western Iraq to encourage Sunni tribesman to turn against al Qaeda and align with American forces.
Petraeus will head to his new job as director of the CIA.
American officials in the U.S. have trumpeted success in reclaiming Taliban strongholds in southern Afghanistan and training Afghan security forces as signs that they are finally making progress toward peace in Afghanistan. But violent attacks have continued, including a number of high-profile assaults and assassinations in recent weeks.
Three international service members were killed on Monday in a bomb blast in eastern Afghanistan, NATO said in a statement. It did not provide nationalities or further details.
At least 39 international forces have died so far this month in Afghanistan.
The Associated Press contributed to this report.