Alastair Cook's determination buys him time as England captain

Even with an Ashes whitewash fresh in the mind, the fourth evening of the second Test against Sri Lanka was about as low as we have been with the England team for quite a long time.

What we wanted to see on the fifth day, when defeat seemed inevitable, was some fight and character.

We got that and then some.

For England to take it to the penultimate ball of the match, so nearly pulling off the greatest rearguard in Test history, was absolutely extraordinary.

Everyone involved played with real passion and determination and, after everything that has happened in the past six months or so, it was important for England to put up such a fantastic show of resistance.

Analysis

"The criticism of Cook is out of order - it's a few people with an agenda against him. But he is under pressure. He needs to find form with the bat and everything will flow from there.

"I don't think captaincy is a burden. Alastair is a strong character. It does all seem to be getting a little but too much at the minute. Perhaps that's why people need to support him rather than swinging axes."

At the end of it all, to see James Anderson, a man who has seen and done so much in a long career, in tears, was a very powerful image.

That England got so close to saving the game was down to Moeen Ali's outstanding maiden Test hundred.

Not only fighting to save the match, but also for his place in the side, Moeen, a natural flair player, produced an innings of discipline and determination. He could have done no more.

Looked at from an entirely neutral point of view, it was a wonderful Test, made all the more so by the fact it is the second in as many weeks to have such a dramatic finish.

Just like at Lord's, England should have won at Headingley. It is a skill to take the opportunities that present themselves in Test cricket, a skill that, at the moment, England do not possess.

However, despite the defeat, there are positives for England to take, not least Moeen, but also the runs scored by Joe Root, Gary Ballance and Sam Robson, and the hostile pace bowling of Liam Plunkett.

What they need now is for the captain to score some runs.

Which brings us to Alastair Cook, who is under pressure not only for the run of six defeats in seven Tests, but also because of a year-long run of poor form with the bat.

I had dinner with Cook on the second evening of this match and he was his usual, steely self. The manner in which he talked of the future gave no indication that he was considering surrendering the captaincy, and he confirmed as much in some bullish post-match interviews.

But he knows he is under the cosh and the criticism he is receiving is clearly affecting him.

England's James Anderson

England almost became the first side to draw a Test after starting the final day five wickets down

There is an agenda out there, which can be seen by anyone on social media. Cook is not on Twitter but he has been made aware. These personal, vitriolic attacks by some high-profile individuals are out of order and have stepped over the mark.

However, Cook is such a steely individual that they might even make him dig his heels in even more. If that is the case, certain issues need addressing.

The first, most obviously, is his batting. An average of 25 over the past 12 months is well below the standard we expect from the man who has scored 25 Test centuries, more than any other England player.

England need Cook the batsman more than they need Cook the captain, and the man himself will know that his primary job is to score runs.

Although he would not want to give up the captaincy, he knows that, if necessary, someone else could do that job if it meant he could get back to his best at the top of the order.

Secondly, the rest of the England team must take responsibility for their own game because the captain is only as good as those around him.

Test Match Special analysis

"Cook is a really, really nice boy. He's honest and he's straight but his form is suffering. He needs to start scoring runs because it's a results-orientated business.

"He has to have some imagination with his captaincy, one plan can't fit into every situation."

There are more reasons for Cook to continue than the obstinate streak that has made him such a successful batsman.

The England and Wales Cricket Board has invested heavily in him, making Cook the man around which the team will be rebuilt following the Ashes debacle. If Cook quits, the ECB will be very disappointed.

Also - and this is not damning him with faint praise - there seems to be no other viable alternative.

Stuart Broad is not physically fit enough to do the job - he has a long-standing knee injury that will require surgery - Matt Prior is working his way back in to the side and the feeling is Ian Bell is not a natural leader and would be better off left to concentrate on his batting.

A lack of leaders in the England side is one we have talked about for some time. These players hardly ever appear in county cricket, so have little experience of captaincy. For that reason, Cook has been learning on the job.

It has been suggested that he should give up the one-day job, but that is not relevant at the moment - England do not play another one-day international until the end of the India Test series. That is a discussion for another time.

Instead, with Cook still at the helm, England must concentrate on getting the captain and the rest of the team in the right frame of mind for the first Test against India starting on 9 July.

Jonathan Agnew was talking to BBC Sport's Stephan Shemilt.