The first time John Bathgate was shot it was either the force of the bullet or instinct that made him plunge from the pirate boat into the waters of the Amazon. He can't remember which.

But he remembers his precise thoughts when the second shot ripped through his leg as he attempted to drown his assailant by forcing his head under the water.

'I thought, "This isn't going to happen again". I needed to act.

'I felt my way down his arm and it was the one with the weapon in it and I was able to twist it out of his hand. In that process two more shots were fired.'

During his eight years in the Royal Marines the Edinburgh-born 35-year-old had been trained in hand-to-hand combat, but it never looked like this.

Challenge: John Bathgate after his ordeal where he was shot by a pirate during his charity canoe trip in Peru

Wounds: Peruvian Navy treat injured Mr Bathgate

He had never grappled with a gunman in the water, never truly feared for his life and certainly never tried to disarm anyone after being shot twice at close range.

He and his fellow expeditionary Ian 'Yan' Roberts, 34, from Devon, had imagined the toughest stages of their bid to navigate the entire Amazon from its source in Ecuador were well behind them.

In the preceding weeks they had been abducted twice by Peruvian indigenous communities which operated as a law unto themselves and found their fate being decided by village elders suspicious of their motives.

Some thought the two may have come to steal their organs; others thought the 'gringos', as they referred to them, may be prospecting for mining land. It took their best broken Spanish and thorough searches of their canoes and equipment to convince them that they were merely unarmed adventurers aiming to be the first to travel from the highest source of the Amazon to the Atlantic coast.

By the time they had navigated tributaries such as the Pastaza and Marañón rivers and were south of the Peruvian city of Iquitos, the two, who met while serving in the Marines, thought they were on easy street. A few more weeks of paddling around 50 miles a day and the record would surely be theirs.

In fact, the foregoing scrapes were merely the prelude to the fight of their lives.

It began on a wide stretch of the Amazon when they heard the engine of a Peruvian longboat known as a peke peke behind them. In the few minutes that followed, five shots would be fired, three of them hitting human targets. The pirate boat would be capsized and the two British ex-military men would swim to the safety of their canoes which were bolted together to form a catamaran.

And the pirates? They would come to reflect that they had tangled with the wrong people.

Now home in Rosewell, Midlothian, two-and- a-half weeks after the encounter which ended their expedition, Mr Bathgate yesterday gave his first detailed account of the attack by the pirates who he believes not only intended to rob them, but kill them too.

He told the Daily Mail: 'These guys could have asked us to put our hands up and taken all our stuff but we'd have got to the shore and contacted the police and got them arrested for armed robbery.

'So, the way we see it is their plan was probably to shoot us, take our things and hide the evidence. People do go missing there every now and again.'

Luckily, the two friends had already discussed the possibility of a pirate attack on their journey, and both knew their emergency operating procedure.

'The plan was, if this kind of thing happened, we needed to capsize their boat as soon as possible,' said Mr Bathgate, who works as a rope access technician.

It was around 8am on July 30 that the pair realised the boat behind them presented a threat. It was making no attempt to pass.

'It was right on our stern, coming directly towards us, coming closer, then stopping, then coming closer again. That made us aware they were interested in us and they were maybe checking us out, so that got our hackles raised.'

As the boat drew alongside theirs they could see two men, one sitting at the engine and another in the middle of the peke peke, swigging from a plastic bottle of home-made brew.

'He didn't look friendly at all. You can tell when you look in somebody's eyes what they're about and this guy's eyes were blank and dark and heavy-lidded. You could tell he was drunk and maybe on something else too.

'He was just scoping us out, basically. We were being very friendly but then towards the end when Ian got his phone out to use Google Translate, the guy was insisting, "Let me hold your phone" and we were saying no.

'We said, "Look, we need to leave now, we've got a long way to paddle today" and manoeuvred our boat to head downstream so their boat was behind ours and then he held onto the back of our boat.

'Again, we said, "We need to go now," and that's when he pulled the weapon from his shorts.'

Mr Roberts was first to react, jabbing his paddle into the chest of the gunman before he could point the pistol and to throw him off balance.

'Ian then dived into the water, probably to avoid the shots and I've seen that first move and jumped on to the guys' boat to try to wrestle the weapon off him.'

Bathgate with Ian Roberts he took on the daunting task of tracing the route of the Amazon

Remote: Peruvian rainforest where the men were nearly killed

The pirate fired and missed, then shot a second time, hitting Mr Bathgate in the shoulder.

'I'm not sure if the shot knocked me into the water or if I felt it and thought, "Christ, I need to get out of this" and I've jumped in the water.'

As he began to surface, Mr Bathgate realised he was beneath the hull of the pirate boat – but which side should he come up on?

'I needed to surface but because the guy has got the high ground, he could just be waiting for me to shoot me in the head.'

He chose the far side of the boat and, as his head broke the water, he saw his friend and the pirate grappling over the side of the boat. 'Ian later said he was just trying to keep the muzzle of the gun out of his face.

'I saw that and grabbed the guy and pushed him under the water – and that has then capsized their boat as well. I remember having my hand on the guy's head, just trying to keep him under – and that's when the second shot has gone through my leg.'

It could easily have hit an artery and brought a sickening end to the underwater struggle. But the bullet entered just above Mr Bathgate's knee and exited near his hip.

Standing 6ft 1in and supremely fit, Mr Bathgate would not normally struggle to subdue a smaller, drunken pirate even if his assailant was ten years younger.

But he had now been shot twice. Luckily, there was no pain – only adrenaline pumping through him and the knowledge that the next shot could be fatal. 'I had to get the gun off him.'

As he tried to wrench it out of his hand, the gun went off again twice, but this time in the direction of the pirate. One shot caught him in the hip and the struggle was over. The attackers' boat was capsized and the former marines had the gun. They swam back to their catamaran and paddled hard out of the area.

L ooking back on the near-death experience, Mr Bathgate said: 'I didn't find it terrifying but I don't think I was thinking clearly. It was very automatic behaviour from both of us.

'Yan automatically knew what he needed to do, that he needed to put the guy off balance, and my thing was I needed to get that weapon straightaway.

'The fear only started when we thought, "Right, these guys are capsized, but they could easily have mates coming in on another boat". The nearest community was our only hope really, but it could also be where these guys were coming from, so we didn't know if we approached the community if they'd just get rid of us and hide everything.'

Checking the magazine of the gun, they found it still contained four rounds. That was some reassurance as they began putting out SOS signals.

Incredibly, Mr Bathgate filmed a video of himself at this time, displaying the bullet wound to his leg. 'I've just been shot,' he says in matter-of-fact tones.

Ultimately the two were rescued by a Peruvian naval gunboat and taken to Iquitos where the injured Scot spent six days recovering.

As for their families back home in the UK, they endured hours of torment after learning that the two had put out an SOS but knowing nothing more than that.

'This was probably the most harrowing part for Ian and me because the Garmin device gives out a warning to an emergency response team, but it also gives a warning to your emergency contacts. So Ian's girlfriend and my brother both got these emergency signals before we were able to reassure them.'

The following day, when they arrived in a wi-fi zone, they read messages swapped between their loved ones on a WhatsApp group they set up to share their progress on the expedition.

'There was a huge amount of messages on this group, all the mums and dads and brothers and sisters and girlfriends worrying, saying, "Who knows what's happened? There's been a medical emergency".

'So when we read through them, that was the saddest part. It was really heart-wrenching to read that and we wanted to reassure them as soon as possible.'

Mr Bathgate, who is single and deliberately eschewed relationships while he planned his Amazon adventure, said his father David first conceived of the mission to make the near-3,200 mile journey. The 82-year-old was climbing in the Andes in 1968 when he hit on the idea of tracing the entirety of the Amazon's route from drips of water on the Chimborazo glacier in Ecuador to the Atlantic coast of Brazil.

His chance never came and the dream was passed on to his son who, along with Mr Roberts, hoped to fundraise for the Royal Marines charity, Rainforest Concern and several mental health charities.

However, recognising that his shoulder needed proper recovery time, he and his friend postponed their attempt and flew home.

His father and mother Julie, 70, were waiting for him at the arrivals gate in Edinburgh. 'It was the first time somebody has met me at the airport,' he said. 'Both of them gave me a big hug – and said I was looking well.'

John Bathgate was inspired to travel the entirety of the Amazon river by his adventurer father

Bathgate and Roberts (2, 3-L) are pictured alongside a member of the British consulate in Peru and a Peruvian Naval commander

Does he think his military training saved his life? 'It's a tough question because you train as Marines with weapons and we were unarmed, but I think just the fact we had spent so much time with pretty hard blokes and a lot of the time doing physical training, I guess you lose a bit of the fear factor. There's also the fact we're both very fit and were sober as well, which helped against a guy that clearly wasn't.'

He added: 'I'm positive that Ian's quick reaction to stop him from being able to get an aimed shot off first was probably a life-saving move. Between him doing that and me getting the weapon that gave us control, these were the two moments that saved us.'

Back in Scotland, Mr Bathgate's shoulder still needs specialist treatment. 'My brain just doesn't seem to register at the moment that I have a bicep on my shoulder. Hopefully that's not irreversible.'

Assuming it heals, the journey will continue – next time with a larger support team. 'We'll maybe dress a bit more military-like and we might hire somebody that can hold a firearm. We would rather not go with a firearm because it changes the dynamic of an expedition and it will make some of these friendly people we found less friendly.

'Plus, if pirates see us with a firearm, it's a very valuable thing for them to have, so it could make us more of a target. We're trying to figure all that out at the moment.'

What is already crystal clear is that, in choosing to rob two former marines – both expert watermen – the pirates made the gravest of misjudgments.

Mr Bathgate said: 'There was a funny headline in the Peruvian papers that said something like "Pirates attack tourists not realising they are British military".

'According to the Peruvian authorities these guys had been operating for a while so they had been robbing locals.'

Both men were arrested and the one with the bullet wound has required surgery.

But, said Mr Bathgate: 'This doesn't define Peru. It's such an amazing place for people that want to do adventure holidays and it's very safe if you're sticking with tourist groups.

'This happened to us because we were on an expedition, and we were alone and unsupported.'

Even then they came out on top. Certain British adventurers, clearly, are not to be trifled with.