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.

The judge, Clement Phiri, said that Ms. O’Donovan had “showed that she has a plausible defense.” He added that “it appears, prima facie,” that there was no evidence of a plot “to overthrow the government.”

She has surrendered her passport and was ordered not to leave the country. A trial date has yet to be set.

Ms. O’Donovan, of Martinsville, N.J., is a 2014 graduate of New York University’s Gallatin School of Individualized Study and is a project coordinator for Magamba Network, which produces political satire and comedy. She lives in Harare, the Zimbabwean capital.

Prosecutors said that, starting in February, Ms. O’Donovan had “systematically sought to incite political unrest through the expansion, development and use of a sophisticated network of social media platforms as well as running some Twitter accounts.”

As evidence, they cited a tweet posted last month that read, “We are being led by a selfish & sick man,” and included a photograph of Mr. Mugabe with an illustration of a catheter. They say that Ms. O’Donovan had access to the anonymous account, with the handle @matigary, via her laptop computer, and that she used an anonymous web browser known as Orion Router.

Ms. O’Donovan’s goal, prosecutors charged, was to “replicate offline uprisings like what happened in Tunisia and Egypt” in 2011.

The @matigary account — which has accumulated a wide following, including among Zimbabwean journalists, for incisive posts about Mr. Mugabe’s government — has continued to tweet since Ms. O’Donovan’s arrest.

Obey Shava, who is representing Ms. O’Donovan and is a member of Zimbabwe Lawyers for Human Rights, said he looked forward to the start of the trial. Asked how his client was doing, Mr. Shava said, “One cannot be entirely excited as her freedom is curtailed.’’

Ms. O’Donovan’s employer, Magamba Network, which focuses on youth culture and news, describes its vision as “a democratic and just Zimbabwe.” It is funded in part by the Omidyar Network, a foundation established by Pierre Omidyar, the eBay founder.

A social media campaign started by the organization under the hashtag #FreeMartha urges Zimbabweans to call for her release, and is being spread by local and international rights groups.

“Magamba itself has been targeted for the work that we do in new media, social media,” said Samm Farai Monro, one of Magamba’s leaders and a comic known as Comrade Fatso. He speculated that the government had targeted Martha “because she is white and American and so she is an easy scapegoat.”

David McGuire, a spokesman for the United States Embassy in Harare, said it was “monitoring Martha’s case very closely and our Consular Services team has been in frequent, direct contact with Martha since her arrest.”

The arrest came as Zimbabwe’s government, which last month established a cybersecurity ministry, is tightening its control over social media and its potential threat to Mr. Mugabe’s 37-year rule.

The government began a crackdown last year on activists who use WhatsApp and Facebook, leading to some of the biggest street protests in years.

The crackdown has helped keep the nation’s streets quiet this year. But as Mr. Mugabe prepares to run for another term, Ms. O’Donovan’s arrest indicates that the authorities are unlikely to tolerate even the slightest criticism of the aging leader.

Led by Mr. Mugabe’s wife, Grace Mugabe, the president’s closest allies have been closing ranks behind him. This week, they engineered the removal of one of the two vice presidents, Emmerson Mnangagwa, who was regarded as a strong contender to eventually succeed Mr. Mugabe.

In an apparent display of strength, Mr. Mugabe had the airport in Harare, the nation’s biggest, renamed for him on Thursday.

Mr. Mugabe, who helped lead Zimbabwe’s struggle for independence and has ruthlessly outmaneuvered every challenger ever since, has expressed growing frustration with the unpredictable power of social media. Last year, a previously obscure pastor, the Rev. Evan Mawarire, became a symbol of the grievances against Mr. Mugabe’s long rule after posting a video on Facebook. After briefly becoming Zimbabwe’s leading opposition figure, the pastor was driven out of the country and quickly lost his influence.

In September, government officials described social media as a security threat, after false rumors about shortages in the nation’s supermarkets caused panic buying and a spike in prices.

Mr. Mugabe’s longtime finance minister, Patrick Chinamasa, was appointed the new cybersecurity minister last month. It is not known where — or whether — the ministry has a physical office.