The appointment of Kazem Vaziri-Hamaneh, the ministry's current caretaker, was widely seen as a compromise choice for the president.
Ahmadinejad had been pushing for a fresh face to purge a ministry he claims has been run by a "mafia" and for Iran's huge oil revenues to be distributed among the poor.
He won the backing of 172 deputies out of the 259 present in the 290-seat Majlis. Fifty-three MPs voted against and 34 abstained.
Deputies had rejected Ahmadinejad's first choice on 29 August, arguing that the radical nominee lacked experience in a sector which accounts for 80% of the country's export revenues.
The president's second nominee was withdrawn ahead of a vote, while the third was rejected last month.
In a brief speech, Ahmadinejad touted Vaziri-Hamaneh's experience, saying he was "one of the caring, pious and devoted sources of the oil ministry, who has been in different parts of the oil ministry for more than 30 years.
"[Vaziri-Hamaneh is]caring, pious and devoted ... who has been in different parts of the oil ministry for more than 30 years"
"For more than three months he has been running the ministry well," said Ahmadinejad, who appeared confident he would escape another embarrassing no-confidence vote for his nominee.
Born in 1945, Vaziri-Hamaneh has spent his entire career in the oil sector, the backbone of the country's economy.
Iran, holder of the world's second-largest oil and gas reserves with an estimated 12% of global oil reserves, currently produces 4.2 million barrels a day, or 5.2% of the world's production.
Vaziri-Hamaneh has a master's degree in governmental management and began work as a petroleum project engineer in a subsidiary of the ministry.
He became a director of corporate planning in the oil ministry and has served as a board member of the state-run National Iranian Oil Company.
One MP, Sattar Hedayatkhah, said Vaziri-Hamaneh was more competent than previous oil ministers, and went on to chastise the president for proposing a series of inferior candidates.
"The good point is that we've arrived at this position step by step, right from the bottom," he said.
Parliament is controlled by Iran's right wing, but many deputies have voiced unease with Ahmadinejad's ultra-radical style that many fear is pushing the country back into international isolation.
The long-running dispute over the minister has also highlighted divisions within the Islamic republic's dominant right-wing camp, a mix of more pragmatic and moderate conservatives and religious hardliners such as Ahmadinejad.
Deputies have acknowledged that the failure to fill the post has been damaging to investor confidence as well as the Iran's standing within Opec, where it is the number-two producer.
But not all deputies were happy with Ahmadinejad's compromise. MP Rashid Jalali-Jafari complained the new minister was apparently oblivious to the presence of an "oil mafia", pointing to "150 companies which have been set up under the oil ministry for both proper and improper contracts".
Vaziri-Hamaneh is seen as a figure unlikely to upset the volatile international markets, and has also spoken out in favour of improving conditions for foreign investment.
Ahmadinejad, on the other hand, has made clear his desire to see more contracts go to Iranian firms.
President Ahmadinejad's style
has come under strong criticism
Last week, Vaziri-Hamaneh said the oil and gas "buy-back" scheme, set up for contracts with foreign companies in order to overcome a constitutional barrier to them holding equity, should be abandoned.
"But we will definitely have foreign partners in our contracts and we welcome foreign investment under appropriate conditions and prices," Vaziri-Hamaneh said.
Iran's constitution, hammered out after the 1979 Islamic revolution, puts oil and gas within the state sector and forbids concessionary basis or direct equity stake production-sharing agreements with foreign firms.
Analysts have repeatedly said Iran is under pressure to at least tweak the arrangement if it wants to meet targets to boost its oil production capacity from 4.2 million barrels per day to 5.4 million by 2010 and then to seven million by 2015.