Erdogan, a native of Istanbul, was a member of the defunct 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 hatred on religiuos grounds in 1998 based on a public reading of one of the patriotic poems of Ziya Gokalp. Once released from jail, he led a movement to draw his former compatriots from the Welfare Party away from religious rhetoric. They founded the Justice and Development Party in 2002 and subsequently won a landslide election.
Erdogan's appointment as Prime Minsiter 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. Abdullah Gül became a stand-in prime minister and pushed through a constitutional amendment that allowed Erdogan to win a freshly vacant seat in the province of Siirt in a by-election. Gul resigned and Erdogan was appointed Prime Minister by President Ahmet Necdet Sezer.