WASHINGTON, Oct 11 (Reuters) - U.S. troops in northern Syria came under artillery fire from Turkish positions on Friday but none were wounded, the Pentagon said, an incident that highlights the risks to U.S. troops as Turkey wages an offensive against U.S.-allied Kurdish militia.

"The explosion occurred within a few hundred meters of a location outside the Security Mechanism zone and in an area known by the Turks to have U.S. forces present," Navy Captain Brook DeWalt, a Pentagon spokesman, said in a statement.

DeWalt said that all U.S. troops were accounted for after the incident near Kobane, Syria late on Friday.

U.S. troops have not withdrawn from Kobane, he said.

Turkey's Defense Ministry said it had taken all measures to ensure that no U.S. base was damaged while it responded to harassment fire that originated near a U.S. base close to Kobane.

"The firing was ceased as a result of the issue being relayed to us by the U.S.," the ministry said in a statement.

U.S. forces have had a successful partnership with Kurdish YPG militia in Syria to oust the Islamic State group.

"The U.S. demands that Turkey avoid actions that could result in immediate defensive action," DeWalt said.

Turkey's Defense Ministry said there was no firing on the U.S. observation post, adding that it fired in response to an attack on its military posts south of the town of Suruc, across the border from Kobane.

The Chairman of the Joint Chiefs of Staff General Mark Milley told reporters at the Pentagon earlier on Friday that Turkey had been told of U.S. positions in Syria, "down to explicit grid coordinate detail."

Top Pentagon officials stressed the need for Turkey to avoid doing anything to endanger U.S. forces inside Syria, which numbered about 1,000 before the incursion. Although U.S. troops had no intention of firing on Turkey, a NATO ally, the Pentagon noted they had the right to defend themselves.

"Everyone is fully aware that we are the United States military. We retain the right of self-defense," Milley said.

Turkey's offensive began days after U.S. President Donald Trump spoke by phone on Sunday with Turkish President Tayyip Erdogan and ordered U.S. troops to be moved out of the way.

U.S. military officials denied accusations by lawmakers and policy analysts that the Trump administration had abandoned its allies. Turkey says its aim is to defeat the Kurdish YPG militia, which it sees as an enemy for its links to insurgents in Turkey. (Reporting by Idrees Ali and Phil Stewart in Washington; Additional reporting by Ali Kucukgocmen in Istanbul; Editing by Leslie Adler, Grant McCool and Daniel Wallis)