North and South Korean warships exchanged artillery fire in disputed waters off the western coast, South Korean military officials said, in the latest sign of rising animosity between the bitter rivals in recent weeks.

Officials from the South Korean Joint Chiefs of Staff and Defence Ministry said on Thursday that a South's navy ship was engaged in a routine patrol near the country's disputed maritime boundary in the Yellow Sea when a North Korean navy ship fired two artillery shells.

The shells did not hit the South Korean ship and fell in waters near it, they said.

The Associated Press news agency quoted unnamed Seoul officials as saying the South Korean ship then fired several artillery rounds in waters near the North Korean ship.

South Korea was trying to determine if the North Korean ship had attempted to hit the South Korean vessel but missed, or if the shells were not meant to hit the ship.

Officials said that residents on the frontline Yeonpyeong Island were evacuated to shelters, and fishing ships in the area were ordered to return to ports. In 2010, North Korea fired artillery at the island, killing two civilians and two marines.

The North's military had threatened on Wednesday to attack South Korean warships "without any warning" if there was even a "trifle" violation of the maritime border.

'Absurd threats'

The threat came a day after a South Korean naval ship fired warning shots to stop an incursion by three North Korean patrol boats across the sea.

The South's navy urged the North to stop "absurd threats" and warned: "We will mercilessly punish any provocative actions by North Korea".

The North does not recognise the Yellow Sea border, the scene of brief but bloody naval clashes in 1999, 2002 and 2009.

In addition, in November 2010, North Korea shelled Yeonpyeong island, killing four South Koreans and briefly triggering concerns of a full-scale conflict.

In March the North fired hundreds of shells in a live exercise near the sea boundary. About 100 shells dropped into South Korean territorial waters, and the South responded with volleys of shells into North Korean waters.

Cross-border tension has been high for months, amid signs that the nuclear-armed North may be preparing to conduct a fourth atomic test.