A law student threatened to carry out a terror attack in Westminster when HM Revenue and Customs refused to return his passport after he had applied for tax credits, a court heard.

Daniel Osula, 37, who has Irish and Nigerian nationality, sent emails to government departments threatening to “commit a grave and bloodied crime” including a knife attack on civil servants and driving a car at pedestrians, Southwark crown court was told.

When Osula sent the emails he was already facing charges for causing £7,000 of damage in a 20-minute rampage at the High Court.

Prosecutor Gregor McKinley said Osula went to the court on September 20 and filled out a form, but after his application was rejected he “picked up a chair … and smashed it against the bulletproof glass”. He was detained by security staff.

Osula, of Dagenham, pleaded guilty to criminal damage and was convicted at trial of four counts of sending malicious messages.

On Wednesday, he was given a 12-month community order including 30 days of rehab by Judge David Tomlinson, who said it was a “tragic case”.

Osula’s barrister, Stella Harris, said his family was in Galway and his wife is suffering from a terminal illness.