Image copyright Reuters Image caption Mahinda Rajapaksa attended a religious ceremony after resigning on Saturday

Mahinda Rajapaksa has resigned as Sri Lanka's prime minister, seven weeks after he was appointed in a surprise move that sparked a political crisis.

Mr Rajapaksa, Sri Lanka's former president, signed his resignation letter in a ceremony at his house.

Former PM Ranil Wickremesinghe is expected to return to office on Sunday.

The resignation could bring to an end a nearly two-month-long power struggle that has dented confidence in Sri Lanka's stability.

"Since I have no intention of remaining as prime minister without a general election being held, and in order to not hamper the president in any way, I will resign from the position of prime minister and make way for the president to form a new government," Mr Rajapaksa said in his resignation statement.

In October, President Maithripala Sirisena sacked then prime minister Mr Wickremesinghe, replacing him with Mr Rajapaksa.

Harin Fernando, a spokesman for Mr Wickremesinghe's party, told the BBC: "The president has agreed to swear in Ranil Wickremesinghe as prime minister tomorrow at 10am."

He said this would end the political deadlock, remarking that the country and its economy had suffered "huge damage" since the crisis began 50 days ago.

On Thursday, the Supreme Court said Mr Sirisena had acted illegally in November by dissolving parliament and calling snap polls with nearly two years to go until elections were due.

Throughout the crisis, Mr Wickremesinghe has always maintained he is the rightful prime minister.

The crisis, which has provoked brawls in parliament and sparked large protests, has been closely watched by regional power India, as well as the US, China and the European Union.

Mr Rajapaksa, who dominated Sri Lankan politics for a decade until 2015, has an uneasy relationship with the West over the bloody end to the country's civil war in 2009, when thousands of civilians were killed. Both government forces and the Tamil Tiger separatist rebels are accused of grave human rights abuses and crimes.

On Wednesday, parliament passed a vote of confidence in Ranil Wickremesinghe as prime minister.

His party and its allies have a simple majority in parliament - and have argued from the beginning that President Sirisena's actions were unconstitutional.

What are the roots of the saga?

Mr Sirisena was once a party ally of Mr Rajapaksa, and served in his government.

But in 2015, he teamed up with Ranil Wickremesinghe to defeat him in an election and the pair went on to form a coalition government.

However the relationship between president and prime minister turned sour and Mr Sirisena in October turned on Mr Wickremesinghe, sacking him in favour of Mr Rajapaksa, his old ally-turned-rival-turned-ally.

He called Mr Wickremesinghe arrogant and linked him to a controversial central bank bond sale, which is alleged to have led to the loss of 11bn Sri Lankan rupees ($65m; £50m). The president also alleged that a cabinet minister was involved in a plot to kill him and that police had obstructed an investigation.