When I was leading the conclusion of the Shabbat service yesterday, I asked someone to light the Chanukkah candles, who asked me if we rather did havdalah first. I know that in a synagogue setting we start with the Chanukkah lights and only after that we do havdalah. However, how can we light the Chanukkah candle, a seemingly forbidden work, before the havdalah? Why is this reversed order in the synagogue?
The key issue in the question is that by saying the words:
וַתַּבְדֵּל ה' אֱלֹקֵינוּ בֵּין קֹדֶשׁ לְחֹל, בֵּין אוֹר לְחשֶׁךְ, בֵּין יִשְׂרָאֵל לָעַמִּים, בֵּין יוֹם הַשְּׁבִיעִי לְשֵׁשֶׁת יְמֵי הַמַּעֲשֶׂה.
You have distinguished Hashem, our God between the sacred and the secular, between light and darkness, between Israel and the peoples, between the seventh day and the six days of labour.
Artscroll Ashkenazi version with their translation
in Ata chonantanu, one performs havdalah on a level that work is permitted after that (Orach Chayim 294:1 and 299:10). After this one may use transportation to leave before the havdalah at the synagogue or light the Chanukkah candles. Another concern is that out of havdalah and Chanukkah the former is the more frequent, and therefore it should have a priority. However, as a general principle, we try to elongate the sanctity of the Shabbat (Orach Chayim 293:1), and this is one reason, why many people light the Chanukkah candles before the havdalah. The other one is that by lighting the Chanukkah candles in the synagogue the miracle is further publicised (see Mishnah Berurah 2 to Orach Chayim 681:2, but R' Ovadia Yoseif strongly supported this practice too).