President Barack Obama, visiting Israel this week for the first time in his more than five years in the White House, worked to improve what had been a testy relationship with Prime Minister Benjamin Netanyahu.

He also reached out effectively to the Israeli people.

The president deserves credit for his conciliatory efforts.

But Mr. Obama also rates praise for fairly reminding his Israeli hosts that they will never achieve a lasting peace with the Palestinians without the creation of a viable Palestinian state.

During a speech to Israeli university students in Jerusalem on Thursday, this line from the president even drew a standing ovation: “The only way for Israel to endure and thrive as a Jewish and democratic state is through the realization of an independent and viable Palestine.”

President Obama had already said on Wednesday that Israel’s expansion of settlements on lands claimed by the Palestinians in East Jerusalem and the West Bank was not “constructive” or “appropriate.”

However, he conspicuously stopped short of repeating his previous calls for that construction to cease. Instead, he issued a general appeal for renewed talks on the “core issues” of establishing a Palestinian state — and of assuring Israeli security.

And as President Obama said Wednesday: “In this work, the state of Israel will have no greater friend than the United States.”

As for the settlements, Israeli officials noticed the softening of the president’s public statements about them.

So did Palestinian officials. As President Obama listened alongside him during a joint news conference on the West Bank on Thursday, Palestinian Authority President Mahmoud Abbas condemned the settlements as an “ignoble” obstacle to peace.

President Obama concluded his three-day trip on Friday with an emotional stop at Israel’s Yad Vashem Holocaust Memorial. Visibly moved, he relit an eternal flame, laid a wreath and invoked humanity’s collective duty “not just to bear witness but to act” against the forces of evil that perpetuate such hate-spawned horrors.

Yes, the Mideast remains a major mess beyond the Israeli-Palestinian impasse. Iran is moving ever closer to a nuclear arsenal, with Israel and the U.S. increasingly considering military action to thwart that goal. Syria’s civil war is taking an immense toll on its people while further destabilizing the entire region.

But President Obama gained some positive ground this week.

He even persuaded Prime Minister Netanyahu to apologize to Turkish Prime Minister Tayyip Erdogan on Friday for a 2010 Israeli naval raid that killed nine Turks.

Meanwhile, despite President Obama’s apparent shift toward a more pro-Israel position, he rightly urged both the Israelis and Palestinians to return to the negotiating table. He also reiterated the futility of any proposed solution that doesn’t include a Palestinian state.

During that Thursday speech in Jerusalem, Mr. Obama told his Israeli audience of their Palestinian neighbors: “Put yourself in their shoes — look at the world through their eyes.”

That’s good advice.

And though President Obama’s previous foreign-policy record has been spotty, he had a productive trip.