NASHVILLE — It was an abrupt and disappointing end to a mayoralty for which many in Nashville had once harbored great hopes.

On Tuesday, Mayor Megan Barry brought her two-and-a-half year run as the city’s first female chief executive to a dramatic close, pleading guilty to a felony charge of theft of property and announcing her resignation. The move capped a turbulent five weeks in which she acknowledged having an affair with the head of her security detail, and faced persistent questions about whether she misspent taxpayer money.

Ms. Barry, 54, had wowed Nashville’s large contingent of liberal voters during a 2015 election with her support for gay rights and a promise to bring a world-class transit system to a city where rapid growth and a burgeoning reputation as a hub for young creatives have generated both excitement and anxiety.

But Ms. Barry’s wonkish policy goals were eclipsed by details of her affair with former Sgt. Robert Forrest Jr. of the Metro Nashville Police Department, who led the mayoral security detail before retiring in January. Mr. Forrest also pleaded guilty on Tuesday to the same charge as Ms. Barry’s.