When Graeme Smith arrived in Afghanistan in 2005, he drove across the country from Kabul south to the Talban's former capital Kandahar on a newly paved road that cut travelling time from a bone-rattling 14 hours to just six.

Today, 13 years after the U.S.-led invasion toppled the Taliban's brutal regime, and after billions of aid dollars flowed into one of the world's poorest countries, making that same 460-kilometer (300-mile) trip would be like signing his own death warrant, said Smith, Afghanistan analyst with the International Crisis Group, an independent conflict resolution organization.

"That journey is back up to being a treacherous 11-hour slog because of all the explosions that have damaged the route and because you're frequently stopped at Afghan security forces checkpoints and Taliban checkpoints. So it is completely suicidal for a foreigner like me to drive on that road now and will probably remain so for a long time as the insurgency rises," he said.

With U.S.-led forces shifting to a supporting role at the end of this month, Afghanistan will have to chart its own course after the country's bloodiest year since the 2001 invasion, a year which saw record casualties among Afghan civilians and security forces alike.

There is cause for measured optimism — a new president has vowed to overhaul the government, root out corruption and mend ties with neighboring Pakistan, where the Taliban is long believed to have enjoyed safe haven. But President Ashraf Ghani faces a monumental challenge in trying to reform the notoriously corrupt government and security forces, and the Taliban have vowed to keep fighting until the last foreign soldier departs.

The U.S. and NATO are set to withdraw most combat forces from Afghanistan on Dec. 31. From a peak in 2010 of 140,000 troops, they are leaving behind 13,500 for training and battlefield support.

They are also leaving behind a war as hot as it has been at any time since 2001. This past year was the deadliest for Afghan civilians since the insurgency began soon after the Taliban were removed from power. Civilian casualties for this year are on course to hit 10,000 for the first time since the U.N.'s Afghanistan mission started keeping figures in 2008.

Nicholas Haysom, the top U.N. envoy in Afghanistan, said that in the 11 months leading up to Nov. 30, there were 9,617 civilian casualties in Afghanistan — 3,188 deaths and 6,429 injuries. Taliban attacks are believed to have caused 75 percent of the casualties.

With U.S. and NATO forces no longer going on the offensive, the insurgents are seizing territory across the country, redrawing battle lines through towns and villages and putting civilians at heightened risk, according to Emanuel Nannini, program coordinator in Kabul with the international aid agency Emergency.

Afghan security forces are also falling in record numbers as they take on a greater role in the fighting, with some 5,000 killed this year alone — compared to some 3,500 foreign forces, including at least 2,210 U.S. soldiers, killed over the past 13.

Efforts to roll back the Taliban could receive a powerful boost from a thaw in relations with neighboring Pakistan. Afghanistan and Pakistan were bitterly divided during much of the 13-year rule of Afghan President Hamid Karzai, with each accusing the other of supporting insurgent groups operating along the porous border.

Ghani has sought a reset in relations, hoping that Pakistan can contribute to eventual peace talks with the Taliban. His efforts received a powerful boost in the wake of the school massacre this month in the Pakistani city of Peshawar, which brutally underscored the shared threat posed by the Taliban and its Pakistani offshoot, which claimed the attack.

The day after the massacre — in which more than 140 people were killed, mostly children — Ghani met Pakistan's army chief, Gen. Raheel Sharif, in Kabul and committed to join hands against the Taliban.

Both Ghani and Pakistan's Prime Minister Nawaz Sharif have insisted there would no longer be distinctions made between good and bad insurgents, a tacit reference to what analysts describe as a longtime Pakistani policy of battling its own insurgents while turning a blind eye to the Afghan Taliban.

"There will be a moment of truth for both leaders," a Western diplomat said. "It would be very unfortunate if they cannot agree to something — if they can, it will be a step forward; if they can't it will be a step backward. There's no neutral ground here."

The diplomat spoke on condition of anonymity to discuss internal Afghan affairs.

Afghanistan's troubles go far beyond the insurgency. This year's protracted election heightened uncertainty and slowed investment, with the local currency sinking from around 50 afghanis to the dollar at the start of the year to around 58 today.

The cost of living has risen as the country relies on imports, and economic growth that was in double-digits just two years ago has plummeted with the cut in aid money that has accompanied the military drawdown. The U.S. Congress cut civilian assistance to Afghanistan to $1.12 billion for this fiscal year, less than half the $2.29 billion spent last year. President Barack Obama has requested $1.59 billion for 2015.

Nader Nadery, the head of the Afghanistan Research and Evaluation Unit, an independent think tank, said that by the end of the year gross domestic product growth will have plunged to below zero. "This is a very, very worrying indicator," he said.

The trajectory of the past decade has not been all downhill, however.

The World Bank says that in the decade leading up to 2012, GDP per capita rose from $186 to $688 and primary school enrollment rose from 19 percent to 72 percent. Maternal mortality nearly halved and life expectancy rose significantly.

"No one seriously disputes that today a woman in Afghanistan is less likely to die giving birth to a child, that the child is more likely to reach the age of five years old, and having reached the age of five that child is far more likely to have a chance to go to school," Smith said.

But there is still a long way to go. Afghans must travel abroad for complex medical care, Nadery said, and the skills needed for sectors with economic potential, such as the mining industry, will lag the rest of the world for at least another five years.

The U.S. has spent $100 billion on reconstruction alongside the $1 trillion war. But due in large part to astonishing levels of waste and graft, Afghanistan's government will end the year strapped for cash. It relies on foreign largesse to pay civil servants' salaries as well as to maintain the army, paramilitary and police forces.

Nadery says the challenges in 2015 "will be immense."

"But taking into account all the foundations there are for the Afghan National Security Forces, one could be cautiously optimistic that they will be able to keep the Taliban at bay and to not allow them to take over."