They had bartered with the local Afghans, swapping pens for cooking oil, potatoes and cans of Coca-Cola. This was the last supper, they joked, and the chips, fried in large ammunition tins set over flammable blocks, were, they said, "the sweetest you could ever taste". That night's operation - to push the Taliban farther south towards the Pakistani border - would be their very last of the tour, before the next day's handover to the Grenadier Guards. It would end up being one of the most intense single firefights undergone by any British army unit serving in Afghanistan in the past six years, leaving two soldiers dead and seven injured, three very seriously.

The chips were served with a pot of ravioli, put away for a special occasion, mixed with anything edible lying around. It beat army rations by a long shot. A drill was converted into an electric whisk and dessert was pink Angel Delight sent by one soldier's mother.

The next day A (Grenadier) Company, the 2nd Battalion the Mercian Regiment (Worcesters and Foresters), was due to leave the perilous Garmsir area in southern Helmand province and fly up to the relative comfort and safety of the British army base at Camp Bastion. From there they would fly home, bringing to an end their six-month tour. A Company was close-knit, but the lads of 1 Platoon felt they had such a special bond they nicknamed themselves the Spartans - "because we really are warriors". Some had gone as far as burning an S into their calves, their branding tool improvised with scavenged wire heated over a naked flame, videoing the ceremony for posterity.

Most of the soldiers had just come into Forward Operating Base Delhi after weeks in outlying positions where they were being shot at and rocketed around 10 to 15 times a day. Out there they slept in their body armour, so the chance to pull on flip-flops and shorts and take a breather in the 50C heat was a relief. Some helped with peeling the potatoes, others sat around listening to iPods, fiddling with night vision equipment or just taking some quiet time out. But the atmosphere was a little edgy: a soldier becomes more superstitious during the final days. "It's like going to a casino; every time you roll the dice, you're raising the probability of getting hit. Towards the end of a tour, you get probability compression," says Major Simon Boyle, the company's current commander. "You don't want to be the last bloke to die."

That night, 1 Platoon Sergeant Michael Lockett felt it, too. "I had been to the sergeant major," Lockett says. "We had a brew and a fag and we said, 'Summat's just not right.' Little things like that were building up in people's minds. They were confident and they knew what they were doing, but they were still worried."

After eating, it was time to get ready for battle. They got kitted up and camouflaged their faces with green, brown and black paint. As they waited, Private Matthew Carlin began chanting his unofficial company song, to the tune of When The Saints: "Go into war,/Go into war,/With A Company,/A Company is going to war,/We're gonna beat and kill the ragheads,/A Company is going to war."

Carlin, 22, becomes embarrassed belting it out now, some months later, in the mess in Cavalry Barracks in Hounslow, but through his blushes he admits that that night he really was a morale booster. "We all formed a circle, about 40 of us, and everyone who wanted to make a tit of themselves got in the circle and started break-dancing and stuff in the sand, and everyone was there whistling with their head torches flashing on and off, creating a sort of disco," he says. "Everyone was just having a right laugh. The whole company was singing the song at the top of their voices. I would stand in the middle and shout it out, and the whole company would repeat it back, with clapping effects as well."

The officers and NCOs stood on the sidelines, smiling at the soldiers, many of them just 18, as they took turns to rap and break-dance to the crowd. "I was the party pooper who had to tell them to get their kit sorted and do a last-minute check on them," says Lockett, 27. "I checked the numbers. Suddenly the mood was very quiet and battle discipline was at a maximum. As we left camp, I shouted, 'You all right, lads, everything all right? Happy days.' "

It was last light on Saturday September 7 2007 when A Company marched out of the gates of their base with three platoons of between 22 and 25 soldiers each. Their mission, Operation Pechtaw, was part of a bigger push on the Taliban, which would take the British army farther south than it had ever been - with 1 Platoon at the head. The Garmsir area is close to the border with Pakistan, and the Taliban is said use this frontier as a blooding ground for new fighters before they are moved north to the Upper Sangin Valley.

"Down there, it's a lot like the first world war, with our forward lines, the enemy forward lines and no man's land. The enemy would come into no man's land to attack us," says 1 Platoon commander, Lieutenant Simon Cupples, 25, also known as Boss. "We would go to the edge of no man's land to the enemy's forward line, clear it and destroy it. The aim was to push back the Taliban and make it safer for the British taking over from us in Garmsir."

They had to go less than 1km from base, but it was pitch black and there were massive irrigation ditches to negotiate. Fanning out, the platoons began clearing deserted farms and old agricultural compounds, moving west to east from locations they dubbed Stripped Wood and Three Walls towards Snowdon, a large hill from where the Taliban had launched numerous attacks over the past six months and where they were believed to keep weapons and ammunition. On the southern-most flank was 1 Platoon. It was nearly midnight. Having reached no man's land, they had just gone firm, positioning themselves flat on the ground, when machine guns opened up on them from 30 metres away. Four men in the seven-man section, including the section commander, Corporal Lee Weston, were directly hit, others were temporarily blinded by phosphorous and disoriented. It was nearing midnight.

Not only were they being attacked by bullets and rocket-propelled grenades, but the Taliban were hitting the platoon with "some kind of Chinese firecracker, like a catherine wheel". The air filled with smoke and sand billowed up. The soldiers could see nothing - when Cupples put down his rifle for a second, he had to grope to find it again. Then, just when he didn't want to be seen, the Taliban would fire over a mini-flare to illuminate their targets. Cupples laughs now at the memory: "I had to stamp them out with my boot, and I was thinking, 'This is crazy, I'm fighting for my life and I'm trying to put out a fire.' "

Lockett recalls: "There were people going everywhere. You don't know if they are falling over or getting down, you don't know what's going on. There was five or 10 seconds of massive confusion. The next thing I know, I'm being picked up off the ground - I had been knocked unconscious. The rounds were literally going past my face. I remember getting back up and not being able to see anything and then my vision slowly coming round."

Carlin was next to him and when he saw Lockett going down he thought he had been hit. "All hell broke loose - explosions going off all around. I was just lying in a prone position. A round hit Lockett's foot and just put him on his arse. I was really scared at this point. The only way I can describe it is like being in a car crash, but the feeling lasted for hours and you can't get rid of it. I really thought I was going to die. The enemy fire was unbelievable. Everyone thinks the Taliban are just some bums with AK47s, but they are really good soldiers."

The ferocity of the Taliban's attack had taken them all aback. Cupples went straight on to his radio, desperately telling his commanding officer back at base what was happening, trying to work out which of his men were down and where. "Suddenly we were in the enemy's killing area. The bullets were winging everywhere."

Everyone was shouting and screaming to get back. Private Johan Botha, a South African who had joined the British army four years earlier, could not be located. Nor could his fellow soldiers, privates Sam Cooper and Luke Cole.

Over the screaming chaos, soldiers remember Botha's distinctive Afrikaans accent on their personal role radios (PRR), shouting, "Boss, please don't leave me." Cole, who had been shot in the leg, could also be heard shrieking: "They're coming to get him." Cole - a territorial army soldier who was a forklift truck engineer back home - later described how he could see shadows moving and, convinced the Taliban were trying to pull Botha away to their trench, he kept shooting.

Rupert Bowers, a 20-year-old second lieutenant who had finished training just before arriving in Afghanistan the week before the attack, was shadowing Cupples. "I saw the muzzle flash from a single-shot weapon. I got down on to my knee, the Taliban illuminated himself with his own muzzle. I fired two shots. I heard screaming, then he stopped." Beside him, Corporal Ben Umney was reeling after a bullet pierced his helmet and, somehow, stopped short of his skull. Bowers gave him his weapon and set about throwing water into the eyes of privates Kyle Drury and Ben Johnston to get rid of the phosphorus, before dragging them into a ditch.

In that ditch lay Lockett, massively disoriented. "Everything was just crazy," he says. "I spent a good 10-15 minutes accounting for people. I was literally on my back at this time. I just kept talking to my blokes, saying, 'We're all right, keep your fucking heads down, lads, and wait out for my QBOs [quick battle orders]'. I told all of them to check fire - I must have shouted it about 30 times - because we didn't know where any of our lads were and we didn't want a blue-on-blue [friendly-fire incident]. I knew I had casualties and I had to sort out the casevac [casualty evacuation] party. I went down the line shouting for volunteers, but I didn't want to take too many men out and lose men to retrieve men."

While Lockett tried to account for casualties in the ditch, Cupples was still out in no man's land, looking for Cooper, Cole and Botha. Being a commander, it was imperative he moved away from the front of the frontline. "It wasn't happening like I wanted it to happen," he says.

Cupples shouted to Cole to crawl towards him. At that moment the private was shot again, in the stomach, leaving his bowels protruding. "He was crawling slowly away from the enemy," Cupples says. "He was saying, 'Look, I can't do it.' I was encouraging him to talk, but he's now shouting and drawing fire, and I had to tell him to shut the fuck up."

Lockett roared at Cupples through the PRR that he had to come back to the ditch and reassess from there. "But I didn't want to leave three blokes on the ground. I said to Cole, 'Don't worry, I'm sorting it out for you, we have got other sections that are coming to help us.' I had to tell him I was going. For someone injured, to see the platoon commander get up and run off, that would distress him a lot. I said, 'Don't worry, I'm coming back for you, keep your rifle with you, I won't be gone long.' It's quite a hard thing to do. You're then leaving him to fend for himself, and he is very close to the enemy."

When Cupples got back to the ditch, Lockett had the rescue party sorted out. Lockett and Bowers were to go together and Cupples would take lance corporals Jonathan McEwan and David Chandler. They all moved forward in a "run, crawl, walk". Lockett describes it: "We would run and draw fire. It was inevitable they were going to see us coming. We needed to cover as much ground as fast as we could. So it was literally a mad dash for it, then get down and start crawling."

Lockett and Bowers spotted Cooper and Cole 30 to 40 metres away. Zigzagging to avoid gunfire, they ran towards them. Lockett says, "I was shouting to Cole, 'Get the fuck over here, you need to get the fuck over here.' I was absolutely fucking gobbing at him, egging him on: 'As soon as you get to me, you're out of the line of fire.' He was making his way towards me with a morphine autojet, shouting, 'Put this in me', but he wasn't a massive casualty at this point and I was saying, 'No, I haven't got fucking time, I've got fire coming in and I've got to get Cooper.' I said, 'As soon as we get 10m away, I will smash you with that morphine.' If we moved, we were going to get hit. I had a lifespan of about two seconds there."

Cooper, the youngest soldier in the regiment having only just turned 18, looked dead. Bowers had him by the hand, which was stone-cold, and he could smell blood. "We were shaking him and there was a bit of gurgling and he didn't look fucking good," Lockett says. He got his Leatherman knife out of his pocket and began cutting off Cooper's kit. Then Bowers, a tall, thin man, got ready to take the private's limp body on his shoulders.

"Just as I got up to run, a bullet came really close. I did a weird sort of crawling motion, then stood up again and ran with him on my back," Bowers says. "Another bullet came dangerously close and I went face first. I got him to the ditch. Me and Corporal Umney then tried to get a response out of Cooper. I said, 'Cooper, have you got a girlfriend?' Someone said, 'Has she got big tits?' And he lashed out and punched Umney - that was the only response he gave that night."

Meanwhile, Cole had also been dragged back to the ditch , where he was given morphine. The company medic, Private Lee Stacey, looked at Cooper's head and saw the extent of his injuries. Some of his brain seemed to be protruding from his skull. Having pushed it back in, Stacey wound the bandage round and then Bowers dragged him back the short distance to Three Walls.

Three Walls is just what the name suggests - three low mud walls, the remnants of a compound, that provided a little shelter behind their forward lines. There were at one point about 50 men taking cover there. Carlin remembers it well. "I was flapping - I wouldn't lie, I was really shitting myself. Then an RPG went through the wall. My mates were still out there and there was nothing I could do. This was my first proper, proper firefight."

Sergeant Major Peter Lewis and the company doctor arrived at the scene in Viking armoured personnel carriers. Lewis had brought more ammunition as it was running short on the field. They began extracting casualties, triaging them from T1, life-threatening injuries, to T3, walking casualties. So far there were no T4s - dead.

Back at the ditch, Cupples was calling in fire support and mortars, the aim being to clear the Taliban trench. But, landing only 20 metres away, the rounds were heart-stoppingly close. "At this point, the enemy was starting to regroup. I knew they were hurting quite a lot now, but they had got the upper hand initially. We had superior firepower support, too. We could hear them screaming.

"At this point the firing slowed down. You could hear a lot of movement in their trenches, you could hear them coming round to the left, that's when they were trying to outflank us. They started to put down fire at us here. Now that they were trying to regroup, the risk became too great - we didn't have enough firepower to cover us."

Back at base Major Jamie Nowell, commander of A Company, asked 3 Platoon to provide covering fire and to extract Botha from the killing zone, dead or alive. "At that time we classed him missing in action," Cupples says. "We just didn't know."

Craig Brelsford was 3 Platoon's sergeant - Lockett's opposite number and a friend. "I said to him, 'Brelsy, mate, Botha is up there, can you bring the big man back for me?' He's like, 'Don't worry, we'll get him.' I promised at the beginning of that tour that I would bring everyone back. I wanted them to know, 'I will be in your back pocket'; I wanted them to think, 'If anything happens, I'll be all right, Locky will be here in seconds,'" Lockett says.

Three or four minutes later the shout went out, "Man down, man down", over the radio. Brelsford had been shot in the neck. Meanwhile air support had been called in to drop 227kg (500lb) bombs on the Taliban positions, and A Company had 10-15 seconds to get under cover. "We were sat against the wall, with our heads between our knees and they gave us a quick countdown," Lockett says. "Stace, who had been a blinding medic all night, had seen that one of the lads was upset and very scared about what was going on, so he lay on top of him to cover him and give him a bit of reassurance. All you can hear are the massive screeches of the planes coming in. It's low and it's fast and you'll not see; it's a blur. The second 500-pounder had knocked a bit of wall off and it landed on Stacey's neck. Next thing we heard 'man down, man down'. Stacey had been hit. He was walking and we got him on the Viking and out of harm's way."

They were ordered to retreat to base. It was almost 6.30am and light was approaching. Even with the use of thermal sights, aircraft could see no sign of Botha's body. It was feared that the private was now in the Taliban trench or held captive at Snowdon.

Back at camp, the soldiers took off their body armour and helmets. "I had 25 of my platoon walk out the gate that night and I had 16 walk back in - I had lost Botha and eight of my boys were injured," Lockett says. "The lads split up into their own little groups. I could see that everyone was massively upset. There were lads absolutely in tears. We didn't know where Botha was."

Lockett gathered his soldiers around him. "I said, 'Right, boys, close in, I need eight volunteers to go out and bring the big man back. If you don't want to come out, I will fully understand, but bear in mind he went out there with you.' Nearly everyone volunteered."

Cupples commanded the first of three rescue Vikings. "You had to be out of your mind to want to go back into that area to fight. It's a lot for the blokes to do. They only do it because it's one of their own men. They know full well there could be some kind of trap, that Botha could be booby-trapped or the enemy could be watching him and waiting for us to come back."

At 7.30am they went back for Botha. Carlin was in the back of one Viking, part of the snatch team that would, should Botha be located, burst out of the back door and pull him inside. Lewis was expecting hell. "I was almost certain we were going to get some of the same ferociousness when we opened the door." But there was none. The bombs seemed to have done their job.

They found Botha's body about 20 metres from the Taliban trench. The ground was smoking. Botha was dead, still sitting in a firing position. "We got him in the back of the Viking. The doctor just said, 'Lads, he's T4. Sorry, lads, he's dead.' "

Captain Henry Nwume, 30, the doctor, says, "I tried to resuscitate him, but he had no pulse and wasn't bleeding. He had dust on his cornea, which made me think he was dead because you would normally blink or you would tear it up. I told the sergeant major he was dead and one of the corporals started crying, then the other. It was a long journey back. Botha was lying at our feet. We started struggling around to get a poncho to put on him. It was 15 minutes of misery jammed in the back of the wagon with Botha's body. He had taken a round through the shoulder and through the arm, I think it would have traversed a great vessel. I remember the guys asking, 'Do you think it was quick, Doc?' but I don't know."

Sergeant Major Lewis thinks it was a job well done: "It would have made a massive amount of difference if we had lost Botha's body. How everybody felt, getting him back was a massive, massive bonus. I would have been a lot more haunted than I am."

After helping take Botha's body off the Viking, Carlin broke down for three hours. "I just couldn't speak. Never felt anything like it. Every soldier wants a firefight in their corner, and that was mine, but I don't wish it on anyone for the feelings we went through that night." Lewis and Lockett took the kit and weapons off Botha and Brelsford, before putting them in body bags and on to the helicopter to Camp Bastion. "All the way through my army career I have been a stickler for kit and up until that op we had never lost any kit. That op, I think we lost two rifles and some night vision. I wasn't even worried about it. I just had two men dead, so the price of a rifle and some night vision was irrelevant to me," Lewis says. The sergeant major is the last one who can break down in front of the men and it was difficult to keep it together. "I found it hard not to release out there. I wanted to, but you've got to seem to be strong. I can only put it down to the same sort of feelings as when I lost my dad."

"When we got back to base we felt like shit," Lockett says three months later. "Everyone was crying for six to eight hours solid. I had to sit back in a Viking and get it out of me."

A Company were flown up to Camp Bastion the next day and arrived home last October. Private Sam Cooper, 18, has suffered brain damage. He is no longer able to speak and has limited movement down one side of his body. Private Luke Cole is alternately using a wheelchair and walking sticks, but he will never run again. Private Lee Stacey, who was attached to the platoon that night as both a gunner and a medic, has serious neck injuries that mean he will never serve again. The battlefield dead estimate for Taliban was put at 19. Since the start of the war in 2001, a total of 86 British personnel have died, 60 of those killed in action or from wounds sustained in action.

When he talks, to stop himself crying again, Carlin plays with the rubber wristbands on his arm. One states: "Support Worcesters and Foresters in Afghanistan", the other, simply "Spartans". "At the start of the tour we were mates, but now we are like brothers," he says. "And in memory of my brothers, I will never take these off, unless someone has to take them off for me."

· For video interviews with the troops, go to theguardian.com/afghanistan