Mahela Jayawardene hit his 19th one-day international century to help Sri Lanka beat Afghanistan by four wickets and avoid a major World Cup upset.

Tournament debutants Afghanistan sensed a shock after reducing Sri Lanka to 2-2 and then 18-3 in Pool A in Dunedin.

But Jayawardene (100) put on 126 with captain Angelo Mathews (44) and although both departed, Sri Lanka held on to win with 10 balls left.

Asghar Stanikzai with 54 was the top scorer in Afghanistan's 232 all out.

The win was Sri Lanka's first of the tournament following their heavy defeat by New Zealand in the opening match, while Afghanistan remain without a point but above England and Scotland - who meet on Monday - on run rate.

"We really need to raise our standards to compete against the top teams," said Mathews, whose side face Bangladesh on Thursday, with further group fixtures to come against Australia, England and Scotland.

How's stat?

This was just the second time in ODIs that both openers have made first-ball ducks. Zimbabwe v West Indies at Georgetown in 2006 was the first and Piet Rinke and Terry Duffin the batsmen.

Mahela Jayawardene is now joint third on the all-time list of most World Cup hundreds. Sachin Tendulkar is top with six, Ricky Ponting second with five and then Sourav Ganguly, Mark Waugh and Jayawardene with four.

"I am feeling relieved at the moment but I thought we came back well. It was a see-saw kind of game. They started off well and then we pulled it back in the end. I knew I had to stay out there with Mahela to get some kind of stand going."

The 1996 champions made a terrible start to their run chase at the University Oval, losing both openers to first-ball ducks.

Dawlat Zadran trapped Lahiru Thirimanne leg before wicket off the first ball of the Sri Lanka reply and fellow pace bowler Shapoor Zadran had Tillakaratne Dilshan caught behind to leave the Test-playing side in a state of shock.

Hamid Hassan then bowled veteran Kumar Sangakkara for seven, leaving Sri Lanka 18-3, and celebrated with a cartwheel and an exuberant wave to the crowd.

Hassan saw off Dimuth Karunaratne for 23, and that brought the experienced pair of Jayawardene and Mathews together with the score 51-4 after 12 overs.

Jayawardene played with the calmness and authority you would expect from a man playing his 443rd one-day international.

The pair looked like they would complete victory on their own but Mathews was run out in the 41st over attempting a quick single.

Jayawardene brought up his fourth World Cup century two balls later but Hassan revived Afghanistan's hopes by dismissing the 37-year-old just three balls later.

However, Thisara Perera, with an aggressive 47 not out from 26 balls, and Jeevan Mendis (nine not out) came together in a stand of 58 to finish off the job.

How's stat?

Hamid Hassan, playing his 26th match, is the first Afghanistan player to take 50 ODI wickets. He is the joint sixth quickest overall in a list led by Ajantha Mendis of Sri Lanka who took 19 matches.

Afghanistan's innings was the fifth time the top-eight batsmen in the order have all reached double figures in a World Cup innings.

The Afghanistan innings, which ended with two balls remaining in the final over, was built around an 88-run third-wicket partnership between Stanikzai and Samiullah Shenwari (38).

It was not until Stanikzai was dismissed by Rangana Herath with Afghanistan 128-3 in the 28th over, that Sri Lanka started to get a grip on the game.

That marked the start of a collapse that saw Afghanistan lose four wickets for 47 runs in 11 overs, with Sri Lanka's Lasith Malinga and Mathews both finishing with 3-41.

It was Afghanistan's fifth-highest score against a Test-playing nation but their total could have been higher but for poor shot selection.

Captain Mohammad Nabi admitted his team's total was always going to be hard to defend.

"I felt we were short by 30-40 runs. We bowled really well in the first 10-15 overs, and we put pressure on them in the end. We kept them to a tight game, so we are pleased by that," said Nabi, whose team next play Scotland in Dunedin on Thursday.