SANTIAGO, Chile — Chile’s president euphorically waved the note, written deep inside a collapsed mine, that his country waited 17 agonizing days to see: “All 33 of us are fine in the shelter,” one of the trapped miners wrote in red letters.

Authorities and relatives of the miners hugged, climbed a nearby hill, planted 33 flags and sang the national anthem Sunday after a probe sent some 2,257 feet deep into the mine came back with the note. “Today all of Chile is crying with excitement and joy,” President Sebastian Pinera said.

The miners’ ordeal may have just begun: Rescuers say it could take four months — until around Christmas — to get them out.

The men already have been trapped underground longer than all but a few miners rescued in recent history. Last year, three miners survived 25 days trapped in a flooded mine in southern China, and two miners in northeast China were rescued after 23 days in 1983. Few other rescues have taken more than two weeks.

For the moment, however, news that the men even survived a tunnel collapse Aug. 5 outshines all other details.

A video camera lowered down the probe shaft showed some of the miners, stripped to the waist in the underground heat, waving happily. But they weren’t able to establish audio contact, Pinera told reporters at the scene.

Word of the miners’ survival was a rush of good news in a country still rebuilding from an magnitude 8.8 earthquake Feb. 27 and its resulting tsunami, which together killed at least 521 people and left 200,000 homeless.

Hundreds gathered, cheering and waving flags, in the capital’s Plaza Italia where Chileans traditionally celebrate national victories. Along the great length of Chile, people were glued to television and computer screens as the drama unfolded in live feeds from the remote mine.

“I am OK thanks to God. I hope to get out soon,” wrote one of the trapped miners, Mario Gomez, 63. “Patience and faith. God is great and the help of my God is going to make it possible to leave this mine alive.”

Mine officials and relatives of the workers had hoped the men reached a shelter inside the mine when the tunnel collapsed the San Jose gold and copper mine about 530 miles north of the capital, Santiago. But they had said the shelter’s emergency air and food supplies would only last 48 hours.

Rescuers drilled repeatedly in an effort to reach the shelter, but failed seven times; they blamed the errors on the mining company’s maps. According to Gomez’s note, at least some of those probes were close enough that the trapped miners heard them.

Hopes rose after the eighth attempt early Sunday when they heard hammering sounds and sent down a probe. The miners put their two notes in a plastic bag and tied it to the end of the probe. Pinera triumphantly showed the bag to the crowd above ground and read both notes to the crowd above ground.

Gomez wrote that the miners used vehicles for light and a backhoe to dig a canal to retrieve underground water.

The opening that rescuers dug to the miners is not wide enough to haul them out. Rescue equipment brought from outside the country was being assembled Sunday to dig a tunnel 27 inches in diameter through which the miners will eventually be brought to the surface.

The hole already drilled will be used to send down small capsules containing food, water and oxygen if necessary, and sound and video equipment so the miners can communicate better with loved ones and rescuers.