BAGHDAD — Vice President Joe Biden returned to Iraq for the first time in five years Thursday, determined to help calm the country’s increasingly chaotic politics and ensure that the fight against the Islamic State group was not thrown off course by Iraqi infighting.

Biden’s trip, which was kept secret before his arrival, coincided with a tumultuous moment for Iraq and its prime minister, who is battling to hold on to his office amid a paralyzing political crisis, a badly weakened economy and a grinding war against ISIS.

Biden landed in Baghdad on a military cargo plane and was immediately ferried via helicopter to a meeting with Iraqi Prime Minister Haider al-Abadi, where they discussed plans to drive ISIS from Mosul, Iraq’s second-largest city.

“It’s real, serious, and it’s committed,” Biden said of the ongoing military operation and Mosul plans, “and so I’m very optimistic.”

Senior White House officials have touted the recent success of Iraqi forces, backed by U.S. airpower and advisers, in driving the Islamic State out of territory the group seized last summer.

“Militarily the momentum is just clearly in the coalition’s favor against ISIL,” said a senior administration official using an acronym for the Islamic State. “They haven’t had a major military victory in more than a year.”

Iraqi forces have made significant progress militarily against the Islamic State in the past year, taking back 40 percent of the territory lost to the group. Biden’s remarks elided a growing worry among top White House officials that the political chaos in Iraq could begin to undermine the battlefield momentum against ISIS.

Biden’s trip was planned within the past two months, before the political crisis exploded in Baghdad, but the timing couldn’t be more opportune for the United States.

The crisis began when Abadi, who has the strong support of the Obama administration, made a bold push recently to replace politically connected members of his cabinet with a new slate of technocrats and reformers. Abadi characterized the move as part of a broader plan to stamp out corruption amid the budget crisis caused by plunging oil prices.

advertisement | advertise on newsday

When his efforts faltered, thousands of protesters gathered at the gates of Baghdad’s heavily fortified Green Zone and threatened to storm parliament.

“Now is not the time for government gridlock or bickering,” President Barack Obama said last week in Saudi Arabia about the protests.

Biden is also connected to Iraq through his son Beau, who spent a year deployed to the country and who died of brain cancer last year. In a brief meeting with about 200 U.S. Embassy personnel, Biden spoke of his son and his service three times in a 12-minute speech that praised the troops and embassy civilians in the room for their service in the war zone.