The city has for years struggled to curb gun violence and secure the cooperation of witnesses to major crimes.
Williams bested four other former assistant prosecutors, including Dan McCaffery. McCaffery had 29,585 votes, or about 30 percent.
Williams will be the favorite against uncontested Republican candidate Michael Untermeyer in November. Nearly 80 percent of the city's voters are Democrats.
Incumbent Lynne Abraham isn't running.
Get Action News on your website