Erdoğan, a native of Istanbul, was a member of the now-defunct Islamist Welfare Party during the 1980s. He was elected mayor of Istanbul in 1994, where he made a name for himself as a populist, effective administrator, building up Istanbul's infrastructure and transportation grid, while simultaneously beautifying the city. He was tried and convicted of inciting religious hatred in 1998 based on a public reading of one of the poems of Ziya Gokalp. Once released from jail, he founded the Justice and Development Party, which is based on a more moderate version of the Welfare Party's Islamic fundamentalism. It subsequently took 34.3% of the vote in the 2002 parliamentary elections, and due to Turkey's system of allotting seats, won a majority in parliament.
Erdoğan's appointment as Prime Minister was delayed after his party's victory in the elections for legal reasons. The prime minister in Turkey must be a member of parliament and the constitution excluded those with previous convictions from standing. A prominent supporter of Erdogan, Abdullah Gül, became a stand-in prime minister and pushed through a constitutional amendment that allowed Erdoğan to win a freshly vacant seat in the province of Siirt in a by-election. Gul resigned (to become foreign minister) and Erdoğan was appointed Prime Minister by President Ahmet Necdet Sezer.
Erdogan has since provoked some tension with the country's powerful and staunchly secular military by pursuing what it perceives as an Islamist agenda.