HARARE, Zimbabwe — A young American woman living in Zimbabwe will be tried on charges of attempting to overthrow the government of Zimbabwe with a tweet mocking President Robert Mugabe, the world’s oldest head of state.

The arrest of the woman, Martha O’Donovan, 25, has raised fears that the Zimbabwean government is stepping up efforts to control social media ahead of national elections in 2018. Mr. Mugabe, who will be 94 next year, is running for re-election despite his increasingly frail health.

Ms. O’Donovan was arrested on Friday at her home in Harare and charged with subverting the government and undermining the authority of — or insulting — the president. She faces up to 20 years in prison.

But on Thursday, a high court judge in Harare granted bail to Ms. O’Donovan and openly expressed skepticism of the charges against her.