Image caption The ISS has previously had to shift its orbit to avoid space junk

The crew of the International Space Station (ISS) briefly took refuge in escape capsules as a piece of space junk hurtled by.

The debris - a discarded piece of Russian rocket - was detected on Friday when it was too late to move the ISS.

Nasa said the debris was barely close enough to be a threat but that precautionary measures had to be taken.

It is the third time in 12 years that the ISS has faced a possible collision with space junk.

In June, a piece of debris came within 335m (1,100ft) of the platform.

The ISS is currently manned by three Russians, two Americans and one Dutch astronaut.

They were ordered by ground control to move into two Soyuz escape capsules in case the station was hit, but a Nasa spokesman said they were given the green light to return to the main station at 0238 GMT on Saturday.

The "sheltering exercise" was carried out with "due diligence and in a very precautionary and conservative fashion", said the unnamed spokesman.

"Everything went by the book and as expected, the small piece of cosmos satellite debris passed the international space station without incident."

Russia's space agency said the debris had passed the station at a distance of 23km (14 miles).

"The cosmonauts have returned to performing their previously assigned work," an official told Interfax news agency.

Image caption Nasa is tracking some 20,000 objects travelling in low-Earth orbit

Nasa says it is actively tracking some 22,000 pieces of space debris, but there are millions of objects left over from decades of space travel drifting in Earth's orbit.

They range in size from smaller than a centimetre across to large chunks of rockets, defunct satellites or discarded fuel tanks.

All are travelling at several kilometres per second and could cause serious damage to the ISS or vital satellites if they collided.

The single biggest debris-generating event happened in 2007, when China used a missile to destroy one of its own satellites. The explosion created more than 3,000 trackable objects and an estimated 150,000 debris particles.

Then in 2009, a Russian and American satellite collided, releasing tonnes of debris.

Efforts are being made to draw up an international code of conduct for space exploration to avoid such incidents happening again.

The US announced in January that it was backing EU countries in working towards the code to address long-term safety and security concerns and establish "guidelines for the responsible use of space".

Countries backing the code would also commit to exploring space for peaceful purposes only and to not attacking each other's satellites.

But critics say such a code would not be legally binding, and concerns remain about countries being obliged to share information on satellites used for military purposes.

India, China and Russia, all of which have advanced space programmes, have not yet said they will back the code.