Magnificent Moeen Ali scored his maiden Test century for England and came within two balls of saving the second Investec Test against Sri Lanka at Headingley today.

The Worcestershire all-rounder reached three figures off 259 balls in 358 minutes with 16 fours.

He batted all through the final day but suffered heartbreak when last man James Anderson, who defended for 55 balls without scoring, was dismissed off the penultimate delivery of the game from Shaminda Eranga.

Ali was left unbeaten on 108 not out as the Sri Lankans celebrated their first ever series win in England.

But he can take immense pride from his own innings and leading a splendid rearguard action on the final day after England had resumed on 57-5.

He impressed Sky commentators and former England captains David Gower and Nasser Hussain with his calmness in handling a pressure situation in only his second Test.

Ali started his innings at the beginning of play after nightwatchman Liam Plunkett had been dismissed to the final delivery of the fourth day.

His first boundary off Dhammika Prasad was a thick edge through the gulley region and then an attempted drive against the same bowler slid off the face of the bat to the boundary.

But he produced a fine stroke in leaning into a Prasad delivery and off driving for four.

Ali had reached 22 not out when rain and bad light led to a break in play with England on 83-5.

The players returned after an early lunch at 1.30 and Ali's swivel pull for four off Eranga took him onto the 30 mark.

Ali shared a stand of 67 with Joe Root who eventually fell for 31 when he edged Nuwan Pradeep to gulley with the total on 124.

Moeen cover drove Herath to the boundary and then used his feet to loft the same bowler over long on to move onto 49 before completing his half century out of 153-6.

Matt Prior (10) became the seventh wicket to fall when he fended a short ball from Prasad to short leg.

But Al remained defiant and at tea was unbeaten on 56 from 162 balls out of 173-7 with 40 overs remaining.

He was given good support by Chris Jordan (21) in a stand of 60 before the Sussex all-rounder and Stuart Broad (0) both fell lbw to Rangara Herath.

Ali was on 88 when Anderson came to the wicket but he refused runs into typical unselfish fashion to keep the strike as much as possible.

He eventually reached three figures with a leg glance for four off Nuwan Pradeep from 259 balls with 16 fours in six hours.

But the celebrations were muted because he was focused on saving the game – a goal he came so close to realising.