Both Prime Minister Benjamin Netanyahu and Palestinian Authority President Mahmoud Abbas are committed to continuing peace talks, despite grumblings over a lack of visible progress in almost five months of negotiations, US Secretary of State John Kerry said Friday.

Kerry made his remarks at Ben Gurion International Airport before taking off from Israel, after three meetings with Netanyahu and one with Abbas over the last two days.

The secretary dismissed reports that talks were floundering, saying that progress had been made despite the complexity of the issues.

“I believe we are closer than we have been in years to bringing about the peace and prosperity that all the people in this region yearn for,” he said.

Kerry quoted recently deceased South African leader Nelson Mandela’s remark that “it is always impossible until it is done,” saying that the Middle East needed to take that idea to heart.

“Despite the fact that we are discussing really difficult, complicated issues, I am encouraged by the continued commitment of both leaders to the pursuit of peace, and they both underscored their commitment to continue to work through these difficult issues in the days ahead,” continued Kerry. “The naysayers are wrong to call peace in this region an impossible goal.”

He said that the issue currently at hand had to do with security guarantees for Israel. “We’ve gone through a very detailed, lengthy, in-depth analysis of the security challenges of the region, and particularly the challenges to Israel and to the creation of a viable, independent Palestinian state,” Kerry said. “Security is paramount in the minds of the prime minister and his team with respect to their ability to be able to move forward with other issues that have to be dealt with. If Israel’s security cannot be increased through this agreement, it’s very difficult to make an agreement.”

Kerry did not offer further details, but a sticking point appeared to be the fate of the Jordan Valley, the area contiguous with the border with Jordan, where Israel wants to maintain a prolonged military presence. Reports said that the Israeli side rejected plans for some Palestinian control at border crossings as well as a reduced Israeli presence.

Kerry’s visit to the region was his eighth in several months, coming amid statements by Palestinian officials that talks had little-to-no chance of succeeding. Lead Palestinian negotiator Saeb Erekat tendered his resignation last month in protest at Israeli moves, though he agreed to see the talks through to the end.

The talks are scheduled to close out in March.

Unlike previous trips, Kerry brought with him retired US Gen. John Allen and an American plan for security arrangements in the case of a peace deal. The plan, which reportedly included leaving some Israeli troops in the West Bank, was rejected by Ramallah.

The Israel Hayom daily on Friday reported that during Kerry’s visit the sides discussed the issue of an IDF presence in the Jordan Valley — Israel insists on one; the Palestinians refuse — and that the US presented a compromise position, that the Israel Defense Forces would remain temporarily. On the issue of Jerusalem, Israel insisted on a united capital, whereas the Palestinians demanded it as their own; the US presented a compromise position, in which Jerusalem would be rebranded as “Greater Jerusalem” and the Palestinians would have sovereignty over its eastern, Arab neighborhoods.

Kerry, in public statements during the visit, repeated the mantra of the centrality of Israel’s security, both vis-à-vis the Palestinians, and a deal with Iran over its nuclear program, which he said had made Israel more secure.

During a joint press conference on Thursday, Netanyahu reiterated Israeli concerns that a final deal with Iran must deny Tehran the capacity to break out to a nuclear weapon. “It is crucial to bring about a final agreement about the termination of Iran’s military nuclear capability,” he said. “I have expressed my concern since Geneva that the sanctions would begin to unravel, and I think steps must be taken to prevent further erosion of sanctions.”

The US secretary met with Netanyahu and Finance Minister Yair Lapid Friday morning, canceling a helicopter tour with Defense Minister Moshe Ya’alon to meet the prime minister in Jerusalem. Kerry also met with Netanyahu twice on Thursday, sandwiching a visit to Abbas in Ramallah.

While meeting Kerry earlier in the day, Lapid thanked him for his work toward a peace deal.

“Despite the disagreements and discord still ahead, a peace agreement is ultimately in the interest of both sides,” Lapid said.

JTA contributed to this report.