After her trial, she said via her lawyer that she did not regret the path she had chosen. “I hope that everyone will speak up and fight, overcome their own fears to build a better country,” she said.

Ms. Quynh had been on hunger strike for periods during her imprisonment, was harassed by other inmates, and her health had deteriorated, Mr. Gemzell said.

In recent years, authoritarian Vietnam has engaged in a widespread crackdown on online dissent. Amnesty International says that more than 100 people are imprisoned in the country because of critical things they have said or written.

Mr. Mattis was making his second trip this year to Vietnam, a former wartime enemy with which the United States has cultivated warmer relations as part of efforts to offset China’s growing strength. A United States aircraft carrier made a port call in Vietnam in March, the first such visit since American troops withdrew from the country in 1975.

Human rights groups say they worry that the improved ties have overshadowed Vietnam’s continuing abuses of civil liberties.