BAGHDAD, Dec. 22 — As the United States debates what to do in Iraq, this country’s Shiite majority has been moving toward its own solution: making the capital its own.

Large portions of Baghdad have become Shiite in recent months, as militias press their fight against Sunni militants deeper into the heart of the capital, displacing thousands of Sunni residents. At least 10 neighborhoods that a year ago were mixed Sunni and Shiite are now almost entirely Shiite, according to residents, American and Iraqi military commanders and local officials.

For the first years of the war, Sunni militants were dominant, forcing Shiites out of neighborhoods and systematically killing bakers, barbers and trash collectors, who were often Shiites. But starting in February, after the bombing of a shrine in the city of Samarra, Shiite militias began to strike back, pushing west from their strongholds and redrawing the sectarian map of the capital, home to a quarter of Iraq’s population.

The Shiite-dominated government publicly condemns violence against Sunnis and says it is trying to stop the militias that carry it out. But the attacks have continued unabated, and Sunnis have grown suspicious.