LONDON — Alex Salmond, the former first minister of Scotland who for years led a campaign for Scottish independence, has been arrested and charged with two counts of attempted rape and several counts of sexual assault, a public prosecutor said on Thursday.

He was released on bail after a brief initial court appearance Thursday afternoon. The hearing was held in private.

Outside the court in Edinburgh on Thursday, Mr. Salmond said to reporters: “I refute absolutely these allegations of criminality, and I’ll defend myself to the utmost in court.”

Police Scotland began investigating Mr. Salmond, 64, after the Scottish government looked into complaints by two women who said he had sexually harassed them several years ago, an accusation he denies. The outcome of the government’s inquiry was not made public.