(Recasts with comments from Pompeo, details on fighting)
By Nvard Hovhannisyan and Nailia Bagirova
YEREVAN/BAKU, Oct 27 (Reuters) - U.S. Secretary of State Mike Pompeo urged Armenia and Azerbaijan to pursue a diplomatic solution to the Nagorno-Karabakh conflict as fighting in and around the mountain enclave entered a second month on Tuesday, defying a ceasefire brokered in Washington.
Armenia acknowledged overnight that Nagorno-Karabakh forces had withdrawn from a strategic town between the enclave and the Iranian border, an apparent military gain for Azerbaijan.
Both sides accused each other on Tuesday of striking targets outside Nagorno-Karabakh itself in defiance of a truce brokered by Pompeo at the weekend.
Pompeo, in India on Tuesday, spoke separately with Armenian Prime Minister Nikol Pashinyan and Azeri President Ilham Aliyev and "pressed the leaders to abide by their commitments to cease hostilities and pursue a diplomatic solution", the State Department said.
World powers want to prevent a wider war that might suck in Turkey, an ally of Azerbaijan, and Russia, which has a defence pact with Armenia. The conflict is also close to pipelines that carry oil and gas from Azerbaijan to international markets.
Azerbaijan's military gains could make a diplomatic solution more difficult: it rejects any solution that would leave Armenians in control of an enclave that is part of Azerbaijan but populated and controlled by ethnic Armenians.
Armenia says it will not withdraw from territory it views as part of its historic homeland and where the population needs protection.
The ethnic Armenian-controlled Nagorno-Karabakh defence ministry said its military had recorded 1,009 deaths since the fighting erupted on Sept. 27. Azerbaijan has not disclosed its military casualties. Russia has estimated as many as 5,000 people have been killed.
Armenian Defence Ministry official Artsrun Hovhannisyan said in a news conference late on Monday that ethnic Armenian forces had given up the settlement of Gubadli south of Nagorno-Karabakh "to avoid unnecessary losses", but the situation was "not critical".
The two countries agreed to a ceasefire on Sunday when their foreign ministers separately met Pompeo in Washington. But the truce, like two previous ceasefires brokered by Russia, has had little impact on the ground.
Localised battles were taking place along several parts of the front line on Tuesday, the Nagorno-Karabakh defence ministry said in a statement. Azerbaijan's defence ministry described fighting concentrated in three frontline areas.
Shushan Stepanyan, spokeswoman for Armenia's defence ministry, said Azerbaijan had used drones to attack frontier posts near the country's southern border with Iran.
Azerbaijan's defence ministry denied this and said in a statement that Armenia had fired mortars in the direction of the village of Aghband in Zangilan region, east of Nagorno-Karabakh and inside Azeri territory, also near the Iranian border.
Azerbaijan later reported four civilian deaths after shelling in the village of Garayusifli, miles from the conflict zone in the Barda region of central Azerbaijan. Stepanyan, the Armenian defence spokeswoman, denied this.
Iran's foreign ministry said on Twitter that Deputy Foreign Minister Abbas Araqchi would travel to several countries to discuss the crisis. Iranian media said he would visit Armenia, Azerbaijan, Turkey and Russia.
Turkish Foreign Minister Mevlut Cavusoglu and his Russian counterpart, Sergei Lavrov, discussed Nagorno-Karabakh in a phone call. Moscow said they discussed an immediate ceasefire.
The OSCE Minsk Group, formed to mediate the conflict and led by France, Russia and the United States, is scheduled to meet the Armenian and Azeri foreign ministers in Geneva on Oct. 29. Turkey has demanded a bigger role in the mediating body.
(Reporting by Nvard Hovhannisyan in Yerevan and Nailia Bagirova in Baku, additional reporting by Margarita Antidze in Tbilisi, Doina Chiacu in Washington, Parisa Hafezi in Dubai and Tuvan Gumrukcu in Ankara Writing by Robin Paxton Editing by Peter Graff)