HANGZHOU - The United States is committed to bringing the perpetrators of the attempted coup against Turkish President Recep Tayyip Erdogan to justice, President Barack Obama said Sunday.

Ankara accuses US-based cleric Fethullah Gulen of being behind the July uprising. At talks with Erdogan on the sidelines of the G20 summit, Obama said: "We will make sure that those who carried out these activities are brought to justice."

Tensions between the two NATO allies have risen sharply since the failed coup attempt against Erdogan on July 15, with Ankara launching a wide-ranging crackdown and demanding that the US extradite Gulen.

An exiled former imam living in the eastern state of Pennsylvania, Gulen strongly denies any involvement with the bid to overthrow Erdogan.

The dispute has soured public perceptions of the United States in Turkey and risks undermining a deep security relationship.

US officials insist they will extradite Gulen if Turkey can present proof he was actually involved.

The meeting in Hangzhou was the two leaders' first face-to-face encounter since the coup attempt.

Obama said the US was committed to "investigating and bringing the perpetrators of these illegal actions to justice" and assured Erdogan of American cooperation with Turkish authorities.

Since July, Ankara has detained, removed, or arrested tens of thousands of people within the judiciary, military, education system and police force for alleged links to Gulen's movement or the coup itself.

US-Turkey tensions have also been strained by Turkey's bombing of Kurdish positions in northern Syria.

The targets included Kurdish groups that are backed by Washington and seen by it as integral to the fight against the Islamic State group.

Ankara accuses them of being in league with the Kurdistan Workers' Party (PKK), a group which has claimed responsibility for deadly attacks inside Turkey.

Obama presses China's Xi on South China Sea

US President Barack Obama pressed his Chinese counterpart Xi Jinping on Saturday on territorial disputes in the South China Sea, urging Beijing to uphold its legal obligations and stressing the United States' commitments to its regional allies. Xi said China would continue to safeguard its sovereignty and maritime rights in the South China Sea, according to a statement on the Chinese foreign ministry's website.

The two leaders and their delegations met for over four hours before Obama and Xi talked one-on-one as they took a night-time stroll.

Tensions over the disputed waters between China and its neighbors were expected to hang over the G20 summit, which opens in the eastern Chinese city of Hangzhou on Sunday.

China is keen to ensure a smooth summit, its highest profile event of the year, as it looks to enhance its global standing and avoid acrimony over a long list of tensions with Washington.

Obama, now in the last five months of his presidency, wants to put a final stamp on his signature policy shift toward the Pacific, setting the tone for his White House successor, who will be elected in November and take office on Jan. 20.

He has invested in developing closer ties with nations in Southeast Asia, and is taking pains in his last scheduled trip to the region to reassure partners worried about the economic and military might of China.

After the meetings with Xi and his top officials, Obama emphasized the importance for China to "abide by its obligations" to an international maritime treaty in the dispute over rights to a territory rich in oil and fish through which $5 trillion in trade travels each year.

An arbitration court in The Hague ruled in July that China had no historic title over the waters of the South China Sea and had infringed on the rights of the Philippines, which brought the case under the U.N. Convention on the Law of the Sea.

Beijing rejected the ruling and accused the United States of stirring up trouble in the sea where China's territorial claims overlap in parts with Vietnam, the Philippines, Malaysia, Brunei and Taiwan.

However, Xi said in his talks with Obama that China "will persist in peacefully resolving disputes through consultations with parties directly involved". He urged the United States to "play a constructive role" in the peace and stability of the region.

In an unusually lengthy statement following the meeting, the White House said Obama had "underscored the United States' unwavering commitment to the security of its treaty allies."

"The president reaffirmed that the United States will work with all countries in the region to uphold the principles of international law, unimpeded lawful commerce, and freedom of navigation and over-flight," the White House said.

China's Foreign Ministry, in a separate statement, said the United States should drop its "double standards on the South China Sea" and play a constructive role in maintaining regional peace and stability.

Obama is at his last summit of the world's 20 major economies, and the White House said the Hangzhou visit would likely be his final meeting as president with Xi, with whom he has grappled over hacking incidents, commercial tensions, and differences over human rights.

Obama stressed the need for a "an open trade and investment environment" and "the need for China to protect religious freedom for all of its citizens," the White House said.

China rejects criticism of its human rights record, arguing it has lifted millions out of poverty.

Cyber issues, from concern over hacking and cyber espionage to emerging Chinese policies on information technology that foreign companies fear could limit their operations in the country, have also strained ties.

The visit got off to a rocky start when a Chinese government official angrily scuffled with Obama's top national security adviser, Susan Rice, at the airport, and yelled at a press aide.

Obama and Xi tried to strike a cooperative tone, formally agreeing to join the Paris agreement to curb climate-warming emissions, a deal they worked together to cement.

But then they got down to more thorny issues. For his part, Xi told Obama that China objects to the deployment of a US missile shield in South Korea to help protect against the North Korean nuclear threat.

Xi also told Obama it was the responsibility of China and the United States to carry out a successful G20 summit and to "inject momentum to the global economy while lifting confidence," Xinhua said.

After lengthy discussions in which they were flanked by their top security and economic advisers, the two leaders talked one-on-one as they took a stroll around the picturesque West Lake, where Xi is hosting the G20 summit.

Video footage of the walk showed Xi asking Obama about his daily exercise routine, and describing growth and change in the region as the leaders sat down for tea.

"We're also setting the stage so that the next US administration comes in with a relationship that is on a strong and productive footing," Obama told Xi.