Iraq has reclaimed its place as the second-largest oil producer in the Organization of Petroleum Exporting Countries, overtaking Iran for the first time in 24 years and shifting the balance of power in the group.

After years of conflict and poor security,
Iraq has finally begun to rebuild its shattered oil industry. In July, it pumped just over three million barrels a day, an impressive 400,000 barrel-a-day increase since the end of 2011, according to OPEC data.

But the shift in rankings also is because
Iran 's output has declined. Western sanctions, aimed at pressuring Tehran over its nuclear program, have cut 700,000 barrels a day from the country's production since 2011, according to OPEC data.

Before the first of the sanctions were imposed in January,
Iran was producing 3.5 million barrels a day of oil, a level Iraq doesn't expect to reach until next year.

The gap between the two countries is likely to widen further in the coming months as
Iraq sees more rewards from contracts signed in 2009 and 2010 with large Western, Russian and Chinese oil companies to develop a dozen neglected oil fields in southern Iraq . These include some of the world's largest, like Rumaila and West Qurna .

The recovery in
Iraq 's oil output because of these deals was gradual at first, averaging 4.2% annual growth between 2006 and 2010. It kicked into high gear last year, as oil production expanded 12.5%.

This is good news for oil consumers. Extra supplies from
Iraq helped global markets cope with the loss of Libyan exports during last year's civil war. It also helps offset the loss of Iranian exports this year.

But so far,
Iraq has just been making up for many years of oil-industry neglect. It still has plenty of growth potential.

"
Iraq sits on very bountiful oil reserves [estimated at 143 billion barrels], and for decades there was too little investment to develop these," said Samuel Ciszuk, an analyst at the U.K.-based consultancy KBC Energy Economics. "So the capacity to lift production even significantly above today's levels is there."

Oil Minister Abdul Kareem Luaiby said recently that
Baghdad is aiming for output of 3.4 million barrels a day by the end of this year. It has loftier plans to produce 12 million barrels a day by 2017. However, despite the recent progress, most observers believe that only a fraction of that five-year target can be achieved.

"As a back-of-the-envelope estimation, one could assume that by 2017 the total could be about 4.5 million barrels a day," said Manouchehr Takin, an oil analyst at the London-based Center for Global Energy Studies. "If we are optimistic, it could be five million barrels a day."

Infrastructure bottlenecks, such as lack of pipeline networks and export terminals, have slowed oil production for years. This problem has eased with the opening at the beginning of the year of two new seaborne oil terminals. But other infrastructure challenges remain.

Boosting oil production further will require injecting a lot of water into fields to restore pressure. Iraqi oil ministry senior officials has been wrangling for years over setting up a new system, which would require huge new investments.

Security is also a problem. Oil-field workers have been relatively safe, but a string of bomb attacks on oil pipelines, including two last month, temporarily halted crude-oil exports from northern
Iraq to the Turkish Mediterranean port of Ceyhan for few days after each attack. The bombings were blamed on the outlawed Kurdistan Workers' Party, which is waging a campaign against the Turkish state in a fight for more autonomy for Turkey 's estimated 14 million ethnic Kurds.

Iraq 's own disputes with its semiautonomous Kurdish region also have held back production. In April, Kurdistan halted 100,000 barrels a day of oil production, claiming Baghdad owed the Kurds $1.5 billion collected from previous oil exports. It resumed exports this month in a goodwill gesture to Baghdad , but may stop them again on Aug. 31 if the payment dispute isn't resolved.

Iraq has much to gain if it can resolve these disputes. "Should [ Kurdistan ]- Baghdad oil relations mend, Iraqi exports would indeed grow by about 175,000 to 200,000 barrels a day more" during the third and fourth quarters of this year, KBC Energy's Mr. Ciszuk said.