Karamanid was a Turkmen state in central Anatolia after the disintegration of Seljuq Sultanate of Rûm. The capital of Karamanid state was usually Karaman and sometimes Konya and other cities as well. It was the main rival of the rising Ottoman Empire. The opponents of the Ottoman Turks in Eastern Europe usually sought for alliances with Karamanid to catch Ottomans between two fires.
Background
While Sultan Beyazıt I of the Ottoman Empire was in Rumeli in 1398, Mehmet's father Alaattin Ali raided Ankara, an important Ottoman city. Beyazıt returned to Anatolia, defeated and killed Mehmet's father. Then he laid a siege on Karaman. Mehmet and his brother Bengi Ali surrendered on the condition that the citizens of Karaman would not be punished. Beyazıt jailed both princes in Bursa, the co-capital of the Ottoman Empire. But four years later, he himself was defeated by Timur in the battle of Ankara and Bursa was captured by Timur's grandson who released Mehmet and his brother.
First reign
Following his release, Mehmet returned to Karaman as the bey of Karamanid state. In addition to his father's possessions, he was given a few forts by Timur and soon he began increasing his territory. During the interregnum caused by Timurlane's devastations, Mehmet began occupying Ottoman and Germiyanids. In particular he captured Kütahya the capital of Germiyanids. The Ottoman ınterregnum ended in 1413 when Mehmet I defeated Musa Çelebi in Rumeli. After the victory Mehmet I returned to Anatolia and defeated Karamanids in 1414. Mehmet II agreed to give all Ottoman territory back. Although he tried to infringe the treaty in 1415 he was arrested and had to swear an oath never to infringe again. He kept his promise and peace prevailed between the Ottoman Empire and the Karamanids during 1415-1422 period. But Mehmet II continued to fight in other fronts. He allied himself with the Ramadanids in Çukurova and began fighting against the Dulkadirids, a vassal of Egyptian Mamluks in south east Anatolia. In 1420, he was captured near Kayseri by the Mamluks and was jailed in Cairo, Egypt.
Second reign and death
After the Mamluk sultan died in 1421, Mehmet was released. He returned to Karaman where he declared himself the bey of Karaman. He ruled on the former Karaman territory with the exception of Niğde, where his brother ruled. In 1421, Mehmet I of the Ottoman Empire died, and soon the war between the Ottomans and the Karamanids was renewed. Early in 1423, Mehmet II attempted to take Antalya, a port in south west Anatolia, from the Ottomans. Probably he thought that the new Ottoman sultanMurat II who just survived two rebellions wouldn't fight for the port far from his capital. However, the governor of Antalya was able to defend the city. During the battle Mehmet was killed and his sons lifted the siege.
Trivia
According to a legend, in 1415 when Mehmet II was to forced to swear an oath, he hid a pigeon under his shirt and holding the pigeon he promised that as long as this life continues, there will be no assault to Ottoman lands. This amusing anecdote is probably a fabrication.