Thirty-three miners were trapped underground when part of the San Jose mine in Chile's Atacama desert collapsed on 5 August 2010.
A second collapse on 7 August hampered rescue efforts, blocking access to the lower parts of the mine.
The San Jose mine, 800km (500 miles) north of Santiago, is mined for copper and gold. The main path - or rampa - reaches down to 720m (2,362ft) below the surface.
The collapses, blocking exit routes, had taken place between 400m (1,312ft) and 500m (1,640ft).
Rescue teams drilled a number of exploratory boreholes, sending listening probes down knowing that, despite the collapse of some ventilation shafts, the miners may have survived.
Seventeen days after the accident, rescuers found a note from the miners attached to one of the probes saying "Estamos bien en el refugio los 33" - "All 33 of us are well inside the shelter."
The note referred to a refuge shelter, 700m (2,300ft) down, where the miners had been having lunch when the first collapse happened.
Emergency supplies and fresh water were sent down the borehole to the miners after they had survived on rations for 17 days.
Communications were set up and the miners told the rescue team they had access to about 1km (0.6 miles) of tunnel and had split into three groups to eat and sleep.
Since then, rescuers have sent food and medical supplies, specialist clothing, camp beds and other equipment down the borehole to make the miners' lives more comfortable.
With access via the mine tunnels blocked, rescuers decided the best way of reaching the men was to drill a shaft and winch them to the surface.
Three types of drilling equipment were used - two raise-bore machines, which drill a pilot hole before widening the shaft. And a third drill, normally used in the oil industry, which drills a wide shaft at the first instance.
The pilot hole for the first shaft, Plan A, started on 30 August - aiming for the shelter. Plan B, involving faster machinery, was aiming for a machine workshop a few hundred metres from the refuge and completed its pilot hole on 17 September.
Rescuers dug all three holes at the same time to be sure of getting the miners out as fast as possible, even if one of the pieces of equipment broke.
Communication with the miners has been key to morale and the rescue operation itself. Messages from relatives and supplies have been passed down the boreholes in special tubes nicknamed "palomas" or "doves".
But the miners have also been able to provide rescuers with video updates of conditions in the mine.
The 33 men have split into three groups - Grupo Refugio, Grupo Rampa and Grupo 105 - named after the shelter, the ramp and Level 105 sections of the tunnel where they are trapped.
They have established shift patterns - work tasks involve clearing the debris falling from the pilot hole as the shaft is widened and unloading the dozens of palomas sent down each day.
Rest periods are used for sleeping, writing letters and games - the miners also need to keep fit and slim enough to fit in the rescue capsule.
Life at the surface
Relatives and friends of the 33 miners have gathered at the mine since the accident in an area dubbed Campo Esperanza, or Camp Hope.
Families have been living in tents, with daily meals provided by charities and local authorities.
They also send messages and creature comforts down to the miners, and await their replies, sent back up in the paloma supply tubes.
A school has been set up for the children of the trapped miners living at the camp - following a request from the miners.
Amid scenes of jubilation above and below ground, the Plan B drill finally broke through to the miners' workshop on 9 October.
After a video inspection of the shaft to check the rock's stability, rescuers decided they only needed to encase the first 96m (315 ft).
Sixteen six-metre tubes were welded together to go into the shaft. This will prevent rocks in the looser soil near the top of the shaft being dislodged and jamming the rescue capsule.
A winch and pulley for the rescue capsules will then be installed and the shaft tested before the rescue begins, it is hoped, on Wednesday.
After unmanned test runs and checks on the Phoenix capsule, the rescue operation began shortly after 2315 on Tuesday (0215 GMT on Wednesday 13 October) with Manuel Gonzalez being lowered down the shaft.
Mr Gonzalez was supposed to return to the surface and report on the condition of the rescue shaft, before handing over to a paramedic. However, the miner Florencio Avalos instead got into the capsule and was hauled up.
The miners wore a "bio-harness" designed for astronauts - which monitors their heart rate, breathing, temperature and oxygen consumption - and sunglasses to protect their eyes from the glare of the desert.
Mr Avalos reached the surface at 0010 on Wednesday (0310 GMT) and was greeted by his family, rescuers, President Pinera and the first lady, Cecilia Morel.
The rescue team was soon able to cut the time down between each ascent from an hour to 25 minutes, and by Wednesday afternoon it became clear that the operation would be completed in half the time originally estimated.
President Pinera was also waiting at the head of the rescue shaft at 2155 on Wednesday (0055 GMT on Thursday), when the capsule carrying Luis Urzua reached the surface.
Before the remaining six rescuers started their return journey to the surface, they held up a banner saying "Mission accomplished."