David N. Dinkins left office stunned and frustrated , secure in history as the city 's first black mayor but narrowly defeated for a second term by a man who used the racial violence in Crown Heights , Brooklyn , as an example of a city mismanaged .