BAGHDAD — Outgoing Iranian President Mahmoud Ahmadinejad paid a final official visit to Iraq on Thursday, seeking to emphasize the growing relations between the Shiite-led neighbors just weeks before he steps down from the job.

The Iranian leader is meeting with top Iraqi officials and visiting Shiite holy sites during his two-day visit to Iraq, which is grappling with its worst outbreak of violence in half a decade. Iraq is home to some of Shiite Islam's most sacred shrines and is a major destination for the sect's pilgrims.

Ahmadinejad is just weeks away from handing over power to president-elect Hasan Rouhani, who is expected to be sworn in in early August. That leaves little chance that his visit will lead to major shifts in relations between the countries or their stance toward the Syrian civil war raging across Iraq's western border.

In brief remarks following talks with Iraqi Vice President Khudier al-Khuzaie, Ahmadinejad emphasized Tehran's determination to strengthen ties further with Baghdad while linking his own country's success with that of Iraq.

"The prosperity, progress and security of Iraq are also Iran's prosperity, progress and security," Ahmadinejad said before later holding talks with Iraqi Prime Minister Nouri al-Maliki.

Ahmadinejad previously flew to Iraq in 2008, the first ever trip by an Iranian president since Iran's 1979 Islamic Revolution and the two countries' bloody war in the 1980s. He used that earlier visit to emphasize a new chapter in "brotherly" relations between the one-time foes and take swipes at the United States over the legacy of its 2003 military invasion.

It was a theme he touched on again Thursday.

"We are determined to make use of all available opportunities to develop brotherly relations," Ahmadinejad said.

Ahmadinejad was given a red-carpet greeting by al-Khuzaie upon arrival at the airport in Baghdad. The vice president is standing in for Iraqi President Jalal Talabani, who suffered a stroke in December and has been absent from Iraq's political scene while he receives treatment in a German hospital.

Al-Khuzaie underscored Baghdad's interest in strengthening ties with Iran, saying Iraq "can be a bridge for good relations between the Islamic Republic and the Arab world." Many of the Mideast's Sunni-ruled Arab states are wary of Iran's intentions in the region.

Neither leader made any mention of Syria during a short press conference. They did not take any questions.

Iran is the main regional backer of Syrian President Bashar Assad, whose troops are battling largely Sunni rebels who receive support from Sunni countries such as Turkey and the Gulf states.

Iraq is officially neutral in the conflict, and it has repeatedly called for a negotiated political solution to the Syrian crisis.

The U.S., however, has been pressuring Iraq for months to do more to stop Iranian flights suspected of carrying weapons to Syria from transiting its airspace. Iraqi officials have carried out some spot checks of Iranian planes and say they've found nothing, though they insist that they lack the capability to force Iranian aircraft to land.

Asked about the allegations of arms shipments, Iranian Foreign Minister Ali Akbar Salehi told The Associated Press by telephone that "Syria does not need Iranian weapons." He did acknowledge that Iran occasionally sends humanitarian and medical supplies to Damascus.

Iraqi fighters meanwhile are traveling to fight in Syria. Shiite militants, some of which are believed to be backed by Iran, are fighting alongside regime forces, while Sunni fighters, many of them allied to Iraq's al-Qaida arm, have joined the rebellion.

The outgoing U.N. envoy to Iraq, Martin Kobler, warned this week that the spike in violence roiling Iraq can no longer be separated from the civil war in neighboring Syria because "the battlefields are merging." Attacks in Iraq have claimed more than 2,800 lives since the start of April.

Late Thursday, a bomb exploded near a Sunni mosque in Mahmoudiya, about 30 kilometers (20 miles) south of Baghdad, killing three and wounding nine, police and hospital officials said.

Another roadside bomb exploded earlier in the day as an army patrol passed by near the town of Madain, 20 kilometers (14 miles) southeast of Baghdad, authorities said. That blast killed two soldiers and wounded four others, police and hospital officials said.

The officials spoke on condition of anonymity because they weren't authorized to release the information to journalists.

Iranian state television reported that Ahmadinejad hopes the visit will boost economic cooperation between the two neighbors, which it says now amounts to $13 billion in annual trade. It said Iran aims to finalize a deal to ship 25 million cubic meters of Iranian gas daily to fuel Iraqi power plants, which are still incapable of provide a steady supply of electricity. A new gas pipeline from Iran is expected to open later this summer.

Iraq is a major market for Iranian goods, including cars, construction materials and food products such as tomato paste and ice cream. Those exports provide an important source of hard currency for Iran, which has been increasingly cut off from the world's financial system following multiple rounds of sanctions over its disputed nuclear program.

In a statement following his talks with Ahmadinejad, al-Maliki urged Iranian companies to continue to invest in Iraq's reconstruction, and voiced his appreciation for Iran's help in the electricity sector.

The U.S.-led invasion ten years ago that toppled Saddam Hussein's Sunni-heavy regime set in motion a rapid turnaround in relations between Iran and Iraq, which fought a ruinous eight-year war that claimed hundreds of thousands of lives.

Saddam's ouster put Iraq's majority Shiites in control, and many Shiites who had fled persecution by Saddam and took refuge in Iran returned home. Millions of Iranians now visit Shiite holy sites in Iraq annually, and top Iraqi leaders including al-Maliki have paid visits to Iran.

Still, many Iraqis remain suspicious of Iranian influence in their country. Sunni Arabs in particular resent the government's warm ties with Tehran and some criticize al-Maliki of being too close to the Islamic Republic.