Two other hostages, including the city's deputy mayor and a woman, had been released earlier.
The 24-year-old hostage-taker, who had not been identified, was hurt during the raid, but it was unclear how he sustained his injuries, Sky News reported.
The BBC reported the suspect, who the network said was a homeless man, had been taken to a hospital and said his injuries were not believed to be severe.
More than 200 police officers had surrounded the building for nearly 9 hours, starting about 9 a.m. local time, before the raid brought the incident to its conclusion.
Officials said the suspect, described by Sky News as a psychiatric patient was a known stalker who had been banned from City Hall because he allegedly had harassed a woman who worked there.
It wasn't clear whether the suspect had a real or fake handgun, Sky News said.
The hostage-taker freed one woman soon after the incident started and then released Deputy Mayor Sepp Misslbeck about 5 hours later.
Negotiations with the man went on through the day until about 6 p.m. shots were heard and authorities said the incident was over.
The final two hostages freed were Misslbeck's secretary, who was believed to be the suspect's stalking target, and the city government's complaints manager, German media reported.
Mayor Alfred Lehrmann said the suspect had a history of violent assault and intimidation.
The incident occurred just a few hours before German Chancellor Angela Merkel was to be in Ingolstadt for a campaign event, which was canceled.