Iraq's cabinet approved a wide-ranging military pact on Sunday that will govern the presence of more than 150,000 U.S. troops stationed in the country, a government official said. (UPDATED

Baghdad and Washington have been scrambling for months to reach an agreement that will govern the status of the troops after their U.N. mandate expires on Dec. 31, and decide on a long-delayed pact allowing U.S. forces to remain in the country for the next three years

The cabinet approved the agreement after a two and a half hour meeting with 28 ministers out of 38 voting for it, including Prime Minister Nuri al-Maliki, the official said.

"Both sides have reached an understanding over the contentious issues and the U.S. responses conform to the demands of the Iraqi side," the aide, Ali Adeeb, told Reuters.

The pact calls for U.S. forces to leave the streets of Iraq's towns and villages by the middle of next year and to leave the country by the end of 2011. It will place the U.S. force in Iraq under the authority of the Iraqi government for the first time, replacing a U.N. Security Council mandate.

The Iraqi government has grown increasing confident of its own ability to keep order as violence has dramatically reduced in the country over the past year. Iraqi forces now have command in all but five of Iraq's 18 provinces, and took the lead role in a crackdown on Shi'ite militias earlier this year.

But Iraqi officials acknowledge they still need U.S. military support against Sunni militants in Baghdad and four northern provinces, as well as aid in logistics and fire power.

Once accepted by the cabinet, the agreement must still pass muster in the Iraqi parliament, where the cabinet's political leaders control a majority of seats.

The cabinet balked at passing an earlier draft of the pact last month, instead submitting a request to Washington for amendments.

Washington replied this month with what it called a final offer, removing language suggesting it might keep its troops on beyond the withdrawal date and adding a commitment not to use Iraq as a staging ground for attacks on neighboring states.

Iraq had also complained that language in the pact allowing its courts to try U.S. troops for serious crimes committed off duty was too vague. Adeeb said the issue was resolved.

"Many things have changed on the issue of jurisdiction over U.S. soldiers. Both sides agreed that we should draw up a list in which we will determine what are major crimes" for which U.S. soldiers could be tried in Iraq, Adeeb said.