Wriggling into the £4.99 Primark dress, Barry Delaney never paused to consider what others might think. He and his best pal Kevin Elliott had made a pact and that was all that mattered.

Three years ago, they had agreed that Delaney would wear a dress – the brighter, the better – if Elliott was killed in a action. Their unusual covenant would be realised sooner than either could have expected; private Elliott died last month the victim of a Taliban ambush in Afghanistan.

It was just after 10am last Wednesday when Delaney squeezed into a tight lime-green mini-dress and donned a pair of 99p pink knee-high socks. Then, assiduously avoiding the mirror, the 25-year-old poured a neat vodka – his, and Elliot's, favourite drink.

For an hour Delaney, 25, sat drinking on the pink sofa in the 10th floor flat of a tower block on the western fringe of Dundee. Eight weeks earlier, the two friends had sat there and swapped stories during Elliott's fortnight break from his tour in Helmand province. Then, Elliott , a Black Watch infantryman, had told his friend that he was terrified of Afghanistan, with its innumerable booby traps and a redoubtable enemy that seemed to be getting deadlier by the week. The 24-year-old believed that he would never come back if he returned to Helmand.

Delaney had complained to Elliott that finding a job was getting harder in a city that was no stranger to unemployment – he had scavenged some part-time labouring work, but even that had dried up.

His reminisces last Wednesday were interrupted by the blare of a car horn from the forecourt 120ft below. It was Jonathan Wells in his Vauxhall Vectra, ready to take Delaney to his best friend's funeral. Wells made no mention of Delaney's odd attire during the two-mile drive to St Mary's Church in Dundee's centre.

"He understood our pact, everyone did," said Delaney. Outside St Mary's a 1,000-strong crowd had assembled, but again no one queried why Delaney was wearing a woman's dress to a soldier's funeral.

"There were a few raised eyebrows, a few looks, but everyone was aware of the promise I had made Kevin." Delaney's recollections of the service are scant, but he remembers Elliott's 22-year-old sister, Kirsty, hugging him hard. He also remembers Elliott's grandmother, Margaret, squeezing his hand, telling him everything would be all right.

Most of all, Delaney remembers trying to hold it together as the eulogies were read out at Barnhill cemetery, then the shock of the shots as Black Watch riflemen fired across the grave. Photographs of the burial show Delaney collapsed in graveside grief. "I was bending down to ask him if he liked the dress's colour," he said. His legs gave way as it dawned on him that Elliott would never answer.

The unspoken truth last Wednesday was how fearful Elliott had become in Helmand. The young private was desperate to come home. During his two-week break from Afghanistan in mid-July, the two friends had chatted in Delaney's flat about the war. Normally, Elliott would have preferred not to dwell on Helmand, focusing on the present.

"He was such a livewire, always full of energy. Every moment with Kevin was a good time, he wanted to put a smile on everyone's face."

But that night two months earlier, Elliott seemed perturbed, revealing how he had seen a fellow infantryman reduced to a bloody pulp after stepping on a hidden bomb. He was particularly haunted by another gruesome incident when, under fire and attempting to flee the battlefield, he was compelled to scoop up the body parts and internal organs of a fallen colleague from the dust to carry with him.

When the time came for Elliott to leave Dundee six weeks ago to return to Afghanistan, the soldier was despondent. "He was really scared about going back. At times it seemed like he knew something was going to happen," said Delaney.

Two days before Elliott's death a letter – a "bluey" – from Afghanistan arrived at Delaney's flat. It was from soldier No. 25136352, private Kevin Elliott, who apologised for not writing sooner, explaining in shaky block capitals that things were a little frantic.

Typically, he tried hard to remain upbeat, revealing plans for a three-week holiday in Thailand with his army colleagues if he survived Helmand. Yet alongside the plans to "chill out and sunbathe" the contents betrayed a deep unease. "It's fucking shit, can't wait to get back," admits the soldier.

Elliott was no stranger to war, having served in central Iraq during the Black Watch's controversial deployment to the notorious "Triangle of Death" in 2004. Afghanistan, according to Delaney, raised the stakes higher. Helmand had bred a different level of fear in men like Elliott. "He said it was a lot, lot worse in Afghanistan. It spooked him." Yet, like most serving infantry, Elliott comforted himself with winning the "big two".

"He wanted the two tour medals. To say he had served in the two wars would have made him proud," Delaney said. "Once he had them, it was over."

Despite Delaney's warning that there were no jobs in Dundee, Elliott wanted to leave the Black Watch, admitting that he had no clear idea why British troops were fighting in Afghanistan.

He died in an ambush in Babaji district on 31 August. In the weeks before then, he had even started to say that UK forces should be withdrawn from Helmand. "He didn't blame [Gordon] Brown or the politicians, he just couldn't see why they were there."

The pact was Elliott's idea: a year ago, while the friends were watching Delaney's widescreen television together, he began hypothesising about his funeral. They both laughed at the suggestion of wearing women's clothes and shook on it. It was decided that the dress would be as loud as possible: a pink number with green spots was the suggested colour combination.

The conversation had been prompted by news the previous day that Elliott's unit was going to Helmand. The fear was building, and both were scared about what might happen.

They had been friends since 2005, when they were introduced by Elliott's 22-year-old sister, Kirsty, and hit it off immediately. They had bonded in the drinking dens of Dundee – their favourite haunt was Fat Sam's. They were inseparable except for Elliott's long tours in combat zones.

Delaney had never fancied the army, opting instead for an erratic career of odd labouring jobs since leaving the city's St Saviour's High School as a teenager. Elliott, like many of his Dundee classmates at Braeview School, left at the age of 16 to join the local infantry regiment.

Dundee lies squarely in Black Watch country, with battalions having fought in almost every major British action. Soldiering in the city is celebrated along with military virtues such as sacrifice and loyalty. So far, the reaction to one of Dundee's young men wearing a tight lime-green dress in honour of one of its fallen has been pride.