Iraq has formed its first democratically elected government in more than 50 years, ending three months of political deadlock that has crippled efforts to end violence.