President Obama announced Tuesday that he is reopening the U.S. Embassy in the Libyan capital of Tripoli and returning the ambassador, mixing a pledge to stand by Libya’s post-revolution government with warnings that “difficult days lie ahead” as the country attempts to build a new government and economy.

Beginning his official visit to the U.N. General Assembly, Obama addressed a high-level meeting on Libya, recently rid of long-time dictator Moammar Gaddafi after seven months of civil war.

His message was a defense of NATO’s decision to intervene on behalf of the rebels in order to prevent a threatened civilian massacre, as well as a promise that security and humanitarian assistance will continue until the oil-rich North African nation is stable.

“This is how the international community should work in the 21st century — more nations bearing the responsibility and costs of meeting global challenges,” Obama said.

But Obama also warned that “even as we speak, remnants of the old regime continue to fight.”

Gaddafi, who took power in a coup 42 years ago, remains at large, and pockets of loyalists continue to threaten the weak hold of the Transitional National Council, recognized by the United States as the legitimate government.

White House officials have held up Libya as a model for a kind of American leadership that relies on partnership and persistence rather than unilateral action, and Gaddafi’s ouster provides a partial vindication of the president’s politically difficult decision to open a third military front in a Muslim country.

He praised the Libyan people for seeing through the revolution, adding pointedly, “even after some in the world gave up hope.” Obama’s Republican critics have argued that more assertive U.S. leadership and more military force would have removed Gaddafi sooner, while others fear that the intervention sets a precedent that could draw the United States into future civil conflicts that threaten civilian life.

“Difficult days are still ahead,”Obama said. “So long as the Libyan people are being threatened, the NATO-led mission to protect them will continue. And those still holding out must understand — the old regime is over, and it is time to lay down your arms and join the new Libya.”

In the early days of Libya’s armed conflict, the U.S. Embassy was shuttered and diplomats evacuated by sea. Obama said that this week “the American flag that was lowered before our embassy was attacked will be raised again, over a reopened American Embassy.”

Obama also linked Libya’s post-revolution economy to the building of a democratic government. Many nations reliant on oil are plagued by official corruption, and Obama, in what is a theme of his visit here this week, urged Libya to build responsive institutions as oil revenues and other state assets become available again with the end of sanctions.

“The Libyan people deserve a government that is transparent and accountable,” Obama said. “And bound by the Libyan students and entrepreneurs who have forged friendships in America, the United States will build new partnerships to help unleash Libya’s extraordinary potential.”

Later Tuesday, Obama was scheduled to host a meeting on the Open Government Partnership, a multi-nation effort to promote transparency, press freedom and anti-corruption efforts by harnessing technological advances.

He will also meets with Turkish Prime Minister Recep Tayyip Erdogan, an influential player in many of the administration’s efforts in the Middle East. Once an ally of Israel, Erdogan has become a sharp critic of the Jewish state, a position that hardened last year after a deadly Israeli military raid on a Turkish aid ship bound for the Gaza Strip.

Erdogan has been an outspoken advocate of the Palestinian push for statehood during this General Assembly, a position that puts him at odds with the Obama administration and with Israel.

The leaders will discuss ways to bring Israel and the Palestinians back to direct negotiations, either to head off the statehood resolution or to follow it.