By Saif Hameed and Stephen Kalin

BAGHDAD (Reuters) - Iraq's parliament impeached Defence Minister Khaled al-Obeidi on Thursday over corruption allegations, removing him from office as the army gears up for an assault on Islamic State's de facto capital, Mosul.

Two lawmakers said parliament voted 142-102 to withdraw confidence from Obeidi after questioning him this month about weapons contracts. He had denied the corruption allegations and in turn accused Parliament Speaker Salim al-Jabouri and five other MPs of wrongdoing.

Obeidi, a Sunni Muslim ally of Shi'ite Prime Minister Haider al-Abadi, had spearheaded the military campaign to retake territory that the ultra-hardline Sunni Islamic State group seized in 2014 and said he had cut down on graft including ghost soldiers -- members of the military who do not exist but whose salaries are collected.

"Those who brought Iraq to where it is now have triumphed," Obeidi said in a Facebook post following parliament's vote. "I tried with everything to fight corruption but it appears that its masters are stronger, their voices louder and their actions more enduring."

Lawmakers have accused the Defence Ministry of wasting billions of dollars and weakening the armed forces to the point where they collapsed in 2014 in the face of the Islamic State onslaught under the previous government led by Nuri al-Maliki, who was also acting defense minister.

Thirteen years after the U.S.-led invasion that toppled Saddam Hussein and led to sectarian violence, OPEC oil producer Iraq ranks 161st out of 168 nations in Transparency International's corruption index.

The military is slowly being rebuilt with the support of a U.S.-led coalition, which has been bombing Islamic State militants in Iraq and neighboring Syria. The army and Iranian-backed Shi'ite militias have retaken many areas from the militants, but the biggest test will be the battle for Mosul.

It was not immediately clear how Obeidi's departure would affect that offensive, which Iraqi officials have said could start as soon as next month, a timeline some coalition officials consider too ambitious.

"It will not negatively influence counter-terrorism efforts against Daesh, nor will it hinder the Mosul operation," said senior Shi'ite MP and former national security adviser Mowaffak al-Rubaie, using an Arabic acronym for Islamic State.

Brett McGurk, the U.S. envoy to the anti-IS coalition, said this month that the row between Obeidi and Jabouri would not derail the Mosul offensive.

A Baghdad-based spokesman on Thursday said the coalition remained committed to supporting Iraqi security forces, declining to speculate on the possibility of fallout on the battlefield from Obeidi's departure, which he called "a matter for the government of Iraq".

Critics of the vote condemned Obeidi's questioning as political. Sunni lawmaker Khalid al-Mifraji described the impeachment as "a crack in our war against Daesh".

(Additional reporting by Maher Chmaytelli; Writing by Stephen Kalin, Editing by Robin Pomeroy and Angus MacSwan)