Mayor Nir Barkat said that as he was driving past city hall, his team saw "a terrorist with a knife".
"Along with my bodyguard we immediately jumped out of the car," Barkat said in a statement.
"He (the guard) drew his gun and aimed at him -- we grabbed the terrorist until the police arrived," he said, adding that they also gave the stabbing victim first aid.
Signup to our newsletter and follow us on Facebook and Twitter!
Police said the stabbing took place between the Old City and the western sector's municipality, and that the suspect was an 18-year-old Palestinian illegally in Israel who was "taken in for questioning".
Police said the victim was stabbed in the stomach. A spokesman for Israel's emergency services said he was taken to hospital for treatment.
The motive for the attack was unclear but it came after a series of knife assaults by Palestinians on Israelis.
Last month, a Palestinian with a knife attacked passengers on a morning rush-hour bus in Tel Aviv, wounding 12 people before being shot and wounded by a passing prison officer.
In December, a knife-wielding Palestinian wounded two Israeli police officers in Jerusalem's Old City.