A serving police officer who posted offensive messages online following Baroness Thatcher's death has resigned.

Sergeant Jeremy Scott, who worked in a back-office role for the Metropolitan Police, is understood to have written on social networking website Twitter that he hoped Lady Thatcher's death was "painful and degrading".

Scotland Yard confirmed Sgt Scott had submitted his resignation and it was accepted with immediate effect.

Commander Allan Gibson added: "This officer's behaviour was completely unacceptable and it is right that he has resigned."

Under the Twitter handle @thinbluespeck, which has since been taken down, Sgt Scott said Lady Thatcher's death was "87 years too late" and added that the world was a "better place".

Before resigning, Sgt Scott reported the matter himself to the Directorate of Professional Standards, which is responsible for investigating complaints against officers' professional conduct. His resignation comes after figures from Scotland Yard revealed that three police officers have been sacked for misusing social media over the past five years.

Allegations linked to the use of sites including Facebook and Twitter have been recorded against 75 Metropolitan Police officers since 2009, with 38 of the claims substantiated.

Prime Minister David Cameron on Thursday branded some reaction to the death of Baroness Thatcher as "pretty distasteful". Several "death parties" were held on the day she died, while an online campaign has driven sales of the song Ding Dong The Witch Is Dead to number four in the official chart.

Commenting on the so-called death parties, Sgt Scott reportedly tweeted: "Marvellous stuff! Margaret Thatcher's death greeted with street parties in Brixton and Glasgow."

Asked if he was disappointed about animosity towards the former prime minister, Mr Cameron said: "I think the overwhelming sense across the country - and you can see it yesterday in the House of Commons - is that we are mourning the loss of someone who gave a huge amount to this country, that was an extraordinary leader."