Wallach was an active member of the Whig Party and was elected as such to the Washington Common Council in 1846, serving for two years. In 1849 he was appointed by President Zachary Taylor as U.S. Marshal for the District of Columbia, which made him the chief marshal for the entire United States until removed by Franklin Pierce in 1853. After election to the board of Aldermen in 1854, Wallach joined the Republican Party and ran against Anti-Know-Nothing candidate James G. Berret for mayor of Washington. He was defeated amidst widespread allegations of election fraud. He ran again in 1860, facing Berret a second time, and lost by 24 votes. This time, Wallach took to the newspapers, publishing detailed accounts of the election crimes of which he believed Berret guilty.
Mayor of Washington D.C.
In 1861, Wallach was serving as the president of the board of Aldermen when Mayor Berret was arrested for refusing to take a loyalty oath to the United States, pursuant to emergency Civil War legislation passed by the U.S. Congress. On August 26, 1861, the Washington City Councils elected Wallach to serve out the remainder of Berret's two-year term. He was subsequently elected to three terms in his own right, and served until 1868, the first Washington mayor to serve more than one term since William Winston Seaton. Wallach's mayoral administration coincided with the District's most drastic period of growth, from a small rural village to a crowded metropolis (thanks to the influx of soldiers and massive federal bureaucracy necessitated by the U.S. Civil War. In accommodating the city's swelling population, Wallach established its paid fire department; paved 22,000 feet of road and over 42,000 feet of sidewalks; planned and executed a modernized sewer system, with 33,000 feet of water mains; and doubled the number of public schools. Wallach also submitted several proposals for beautification of the city's avenues and successfully advocated for a Congressional grant to build a modern marketplace in the center of the city. Wallach was mayor when Abraham Lincoln was assassinated in April 1865. He oversaw the police investigation and helped to prevent a riot in the crowds of frightened attendees at Ford's Theater. He later headed the Lincoln National Monument Committee. Wallach was a staunch opponent of both emancipation and suffrage for former slaves, but did act to encourage integration of Washington schools, intending to dispel the idea that only poor children attended public schools. The Wallach School on Capitol Hill was named in his honor in 1864. However, his general lack of sympathy for blacks in Washington resulted in their turning him out of office, since in 1866 Congress had enacted black suffrage above his objections.
Wallach returned to his law practice in Washington, dying in March 1881. Despite his opposition to emancipation and black suffrage, and his status as a slave owner, Wallach did act as the attorney for some slaves petitioning for their freedom in the United States Circuit Court of the District of Columbia. John H. Brooks, a black member on the school board, pushed for resolutions of memorial for the late mayor, claiming that "the colored race owed him a debt of gratitude." In 1864, while he was still mayor, a schoolhouse in SE Washington was named the Wallach School in his honor. It was closed in 1949 and razed the following year.