Alastair Cook defiantly insisted he would carry on as England captain after the dramatic second Test defeat by Sri Lanka at Headingley on Tuesday, but he admitted that he had to learn from his mistakes if he was to avoid being sacked.

His team’s determined fightback eased the pressure on Cook, which after the fourth day had looked as if it might be enough to finish off his captaincy just two Tests into the ‘new era’.

But he vowed to carry on and defended his tenure, despite becoming the first England captain to lose a Test and one-day series at home to Sri Lanka.

"I am in it for the long haul as I believe I am the right man for the job. I never quit on anything.

"I am a determined bloke and I am determined to turn it around. It is a tough challenge. Runs are hard to come by and it puts pressure on me. It is simple.

“I have to use the next 10 days to train hard and score runs against India in those first couple of games.

"Nobody is guaranteed a place in this team. Young cricketers are pushing for places and that is the way it should be.”

He said he would work “incredibly” hard on his batting before the series against India, which starts at Trent Bridge in two weeks time.

Defeat at home by India, who have not won a Test match away from home for two years, would probably spell the end.

“As I keep saying, I am incredibly proud to captain England, but I have been selected to do it,” he said.

“If someone decides I am not the right person and if results do not justify me doing it, then fine. But until then I am desperate to turn English cricket around.”

Cook admitted that the fourth day of this match, when England’s tactics in the field to Angelo Mathews saw momentum shift decisively Sri Lanka’s way was one of the worst in recent times, including the Ashes whitewash.

“We had one of our worst days with bat and ball and we lost the game because of it,” he said.

“If you look at the whole series we had the better of eight days out of 10. But it doesn’t change the fact that we have lost the series.

"We have seen young players come in and do outstanding things but we were 300 for three here in the second innings with a lead of 60.

"We did not nail Sri Lanka down and that cost us. We need to nail those positions.”

Peter Moores, the head coach, said he believed Cook had showed leadership qualities in adversity.

“It has been a tough day for him, but today was a great comeback without actually getting over the line.

"It was led by the captain. He was out this morning speaking to the lads. He fronted up brilliantly and that is an example for the rest of the side.”

There was emotion in Cook’s voice during the post-match presentation just minutes after the dramatic end, but not as much as James Anderson.

Often a snarling, nasty fast bowler with a verbal barb, Anderson was reduced to tears, failing to get through his television interview with Michael Atherton.

“We got quite close and it’s gutting to ...,” he said before the interview was cut short.

“It [his emotion] shows to everyone who doesn’t know us as blokes what it means to play for England,” Cook said.

“We sometimes get accused of not caring when things don’t go well. But that is the raw emotion of a guy who put everything into 83 mins of batting. If it had been 84 I would be sitting here with a big smile.”

Anderson slumped on his haunches when he was caught at leg gully two balls short of saving the match, a result that would have made Moeen Ali, who made an unbeaten maiden century, a national hero. “Obviously I am very gutted,” Moeen said. “I would much rather have got 99 than a hundred and saved the game. Jimmy played brilliantly but the ball was right on the money and bounced.”

Moeen joined Gary Ballance, Sam Robson and Joe Root as young ­batsmen who have made a mark on this series. “It was an incredible effort today to do that,” Cook said of Moeen.

“To see a free-flowing batsman like him play such a controlled, measured innings under pressure can only bode well for the future. It is a great way to announce yourself in international cricket.

“We thought we were getting closer and closer and started believing. James surviving for 80 minutes means it is gutting to come up short.

"The series was very close but they won the crucial moments. Everyone today I can’t fault. We lost this Test match from a really bad day yesterday. Simple deal.”