Nicolas Sarkozy, the former French president, has been formally charged with corruption and illegal campaign financing over allegations that Muammar Gaddafi, the slain Libyan leader, helped fund his 2007 campaign.

After five years of investigation and two days of questioning in police custody, judges looking into the scandal decided they had enough evidence to charge the 63-year-old, who served as president between 2007 and 2012.

He was first taken into custody in the Nanterre suburb west of Paris on Tuesday morning before returning for another interrogation session on Wednesday morning.

"This calumny has made my life a living hell since March 11, 2011," the newspaper Le Figaro quoted Sarkozy as having told the investigators.

He will have six months to appeal to have the charges overturned, which he is likely to do, and the judges will have to make a further decision about whether they have sufficient proof to take the case to trial.

The case is connected to accusations that Sarkozy received money from Gaddafi to fund his successful election bid in 2007, allegations he denies and has dismissed as "grotesque".

The prosecution claims Sarkozy spent nearly double the legal limit of $24m on his campaign, using false billing from a public relations firm called Bygmalion.

An investigation into the allegations has been under way since 2013.

In 2016, businessman Ziad Takieddine told French investigative site Mediapart that he had delivered suitcases containing more than $6m in cash from Libya to Sarkozy and his former chief of staff, Claude Gueant.

"These are the facts, yes ... Gaddafi paid Sarkozy, it paid for the campaign, it paid for other things ...," Takieddine said.

His right-wing Republicans party has so far backed him publicly.

"Friendship and loyal support to Nicolas Sarkozy in this test," the treasurer of his 2007 campaign, Eric Woerth, tweeted.

Amitié et fidèle soutien à @NicolasSarkozy dans cette épreuve — Eric Woerth (@ericwoerth) March 21, 2018

But there have been signs of unease among some senior conservatives who fear being contaminated by the mounting allegations against him.

Brice Hortefeux, a Sarkozy ally who was a top minister during his presidency, was also questioned on Tuesday.

"Mr Hortefeux again assured that there was no financing from Libya or any foreign country," his lawyer Jean-Yves Dupeux told agencies.

This calumny has made my life a living hell since March 11, 2011 Sarkozy

In 2011, as NATO-backed forces were driving Gaddafi out of power, the long-time Libyan leader's youngest son Seif al-Islam, told Euronews network that "Sarkozy must first give back the money he took from Libya to finance his electoral campaign."

Sarkozy has dismissed the allegations as the rantings of vindictive Gaddafi loyalists who were furious over the French-led military intervention in Libya that helped end Gaddafi's 41-year rule and ultimately led to his death.

The former president had also sued Mediapart, which led media coverage of the Libyan allegations since 2012 when it published a document allegedly signed by Libya's intelligence chief showing that Gaddafi had agreed to finance Sarkozy to the tune of 50m euros ($62m).

Le Monde newspaper reported on Wednesday that several other Gaddafi government members had come forward recently with more evidence.

Takieddine claimed he provided 1.5 to 2 million euros ($1.8m, $2m) in 200 euro ($247) and 500 euro ($618) notes each time and was given the money by Gaddafi's military intelligence chief, Abdullah Senussi.

The legal investigation is looking into these allegations, as well as a 500,000 euro ($618,341) foreign cash transfer to Sarkozy's former interior minister, Claude Gueant, and the 2009 sale of a luxury villa in the south of France to a Libyan investment fund for a suspiciously high price.