Updated at 6:05 p.m. ET
Peruvian police say helicopters have ferried out the last tourist stranded near Machu Picchu.
Col. Santiago Vizcarra says 1,277 foreigners were evacuated Friday. He says a total of 3,900 tourists and local people were flown out of the tiny mountain village of Machu Picchu Pueblo this week.
Mudslides and torrential rains on Sunday destroyed sections of the railway that is the only form of transit in and out of the village below the Machu Picchu citadel.
Earlier Friday, authorities rushed to evacuate the last tourists stranded near Machu Picchu.
Fewer than 800 tourists were evacuated Friday on helicopter rides from this Peruvian village outside the famous ruins that are perched on an Andean mountain ridge at 8,000 feet.
The remaining tourists were mostly in their 20s and early 30s.
Flights began as the sun rose to a clear sky over the shaggy, green Andean peaks.
"The sun came out a bit this morning and I hope I can get back to Cuzco today, and then head home to Brazil," tourist Ana Gutierrez said.
Authorities said Machu Picchu will remain closed for weeks until the government can repair roads and railroad tracks washed out by mudslides and the raging Urubamba River.
Authorities evacuated 2,542 travelers before Friday after heavy rains on Jan. 24 caused mudslides that blocked the only land route in and out of the Machu Picchu area.
The hordes of outsiders caught in Machu Picchu Pueblo, a town of 4,000 people, strained food and water supplies.
Hotels overflowed, and travelers grew frustrated over chaotic relief efforts, price-gouging and scarce food. Many were left to eat from communal pots and bed down in train cars, outdoors and wherever they could find space.
Sofie Mag, a 19-year-old from Frederiksberg, Denmark, said a manager at the Sanctuary Lodge, right next to the ruins and a 45-minute bus ride from Machu Picchu Pueblo, let her and other tourists sleep on the floor of the building's restaurant.
"It was free and we got food also," Mag said. "We were very lucky to be up there. ... The first day was chaos."
Authorities closed the Inca trail, a popular four-day trek that ends in Machu Picchu, after a mudslide killed two people Tuesday. The trail also is likely to remain closed for weeks, and is seldom used at the height of the area's rainy season in February.
Rescue efforts have been complicated by bad weather and terrain - the village is wedged between a sheer, verdant mountainside and the Urubamba River. Rain prevented helicopters from landing in the town until after midday both Tuesday and Wednesday, but skies have been clear ever since.
Evacuations were conducted by age - oldest and youngest first.
The last middle-aged tourists left Thursday from a makeshift helicopter clearing, as younger backpackers played football with locals and lent a hand stacking sandbags and clearing train tracks.
When mudslides Sunday destroyed the railway, many hotels and restaurants raised prices exorbitantly. Tourists who could afford to do so paid the higher rates, while others spent days sleeping in train cars and waiting for delayed food shipments.
Dina Sofamontanez, who runs Hostal El Inka, said she dropped prices when tourists ran out of money, while some hotels on the main avenue raised theirs fivefold up to $50 a night.
"It's all about money," she said.
When ATMs ran dry, many backpackers slept in the central plaza.
"We had to eat what the locals gave us, out of communal pots," 34-year-old Argentine tourist Sandra Marcheiani said. "The last few days I've shared beds with other people."
Some 400 Americans were said to be among those stranded when train service initially stopped.
Karel Schultz, 46, of Niagara Falls, said before being flown out Thursday that most Americans paid for beds and bought their own food, while those who slept in the streets were typically Argentines and other South American backpackers.
By Associated Press Writers Andrew Whalen and Martin Mejia; AP writer Martin Mejia reported from Machu Picchu Pueblo, and Andrew Whalen from Lima