Gerry Adams has accused anti-Sinn Fein elements within the British establishment of concocting a claim he sanctioned the murder of an MI5 spy in the IRA.

The Sinn Fein president said he specifically and categorically denied the allegation levelled in a BBC documentary that he approved the killing of Denis Donaldson.

The explosive claim was made by an anonymous man, who claimed he was also a paid state agent in the IRA, to the Spotlight programme.

Mr Donaldson, 55, a Sinn Fein official and close colleague of Mr Adams, was shot dead at an isolated cottage near Glenties in Co Donegal in April 2006 following his exposure as a British spy.

Mr Adams, who said he would have no issue speaking to police to reiterate his denial, said he was consulting with his lawyer about potential legal action against the BBC. The corporation has said it stood by the story.

"That the BBC would broadcast unsubstantiated allegations from an anonymous person, a self-confessed agent, about me, I think is very, very low journalism indeed," Mr Adams said.

He added: "If my legal advisers give me the type of guidance that I require I will sue them. I'm not reluctant to sue."

Responding to the claim as he attended the National Ploughing Championships in Tullamore, Co Offaly, the veteran republican accused "elements within the British system" of trying to undermine him and his party.

"We have to look at what's behind this agenda," he said.

"The person who made this allegation - an anonymous, unnamed, self-professed agent of the British state. So whose agenda is that serving? This is an attempt to rewrite history.

"There are elements within the British system who will never be reconciled with the fact that we have got a peace process and that Sinn Fein are in the leadership of that process, along with others; that Martin McGuinness, for example, leads the administration in the north along with (DUP First Minister) Arlene Foster; that we've got five Sinn Fein ministers (in Northern Ireland); that we are growing here in this part of the island (Irish Republic) and that's what this and what that agenda is about."

Dissident republican group the Real IRA claimed responsibility for the murder in 2009 but the circumstances surrounding Mr Donaldson's outing as a British agent and subsequent death have long been shrouded in mystery.

The man interviewed by Spotlight said the IRA was responsible for the murder and Mr Adams sanctioned it.

Sinn Fein's Mr McGuinness branded the allegation against his party colleague "total rubbish".

"The fact is the Donaldson family are actually very close to all of us within the leadership of Sinn Fein," said Stormont's Deputy First Minister.

"And I think the fact that dissident republicans claimed responsibility for this and it appears for the last 10 years the Garda Siochana in Donegal have been investigating that line of inquiry I think gives total nonsense to the allegation that was made principally by someone who appears to be a paid agent, and I use the word 'agent' in inverted commas."

He said the documentary lacked credibility and insisted the claims would not damage Sinn Fein.

"Sinn Fein have had to deal with programmes like this for the last 30-odd years," he said.

"The important thing for us is the wisdom and intelligence of the electorate is there for everybody to see.

"Even against the backdrop of recurring programmes over 30 years, just a few weeks ago the electorate returned us with the DUP to take the government of the north further on, so I don't believe it's going to damage Sinn Fein in the least."

A spokeswoman for the BBC said: "The Spotlight programme dealt with matters of great public interest and the BBC stands by its journalism."