In the ancient times, Hamadan was known as Ecbatana. Hamadan was once one of the ancient world’s greatest cities. Unfortunately little signs of that elegant time is remain, but significant parts of the city center are given over to excavations and there is a scattering of historical curiosities.

It's interesting to know name of Hamadan is mentioned in the Bible (Ezra 6:1–3), and there is a tradition of Jewish association with the town. The tombs of Esther and Mordecai located there. Tomb of Esther located there is in reality that of Queen Shushandukt, wife of the Sāsānian king Yazdegerd I who died 420 CE and mother of Bahram V, the great hunter. She helped establish a Jewish colony in the city and was herself of that faith. Her tomb and the famous grave of Mordecai, Esther's uncle, are both places of pilgrimage.

The city was captured by the Arabs in 641 or 642. During this period the city was the home of some of the great thinkers and artists of the Islamic period, i.e. the noted great Persian-language poet Baba Ṭahir, whose mausoleum is located in Hamadan. The physician and philosopher Avicenna died in Hamadan in 1037, too.

In the second half of the 12th century, Hamadan was the capital of Seljuq Turkish sultans for 50 years; when the building of Gonbad-e Alaviyyān, a mausoleum with fine stucco work was made.

Hamadan was under some attack later and destroyed by the Mongols and Tamerlane when the inhabitants massacred.

Hamadan was partly restored in the 17th century between Iranian ruling houses and the Ottomans.