Campsites and lodges have emptied out after disappointed tourists were ordered to leave the heart of Yosemite National Park as firefighters battle to contain a huge wildfire.

The blaze just to the west has threatened the park’s forest and sent up smoke that obscured grand vistas of waterfalls and sheer granite faces.

Yosemite Valley will be closed until at least Sunday, along with a winding, mountainous 20-mile stretch of California’s State Route 41 that leads in, park spokesman Scott Gediman said.

At least 1,000 campground and hotel bookings will be cancelled, to say nothing of the impact on day visitors, park workers and small businesses along the highway, he said.

Rangers went to campsites one at a time to inform visitors of the closures. Hotels guests got phone calls and notes on their doors.

“This is the prime visitor season, so this wasn’t an easy decision to make,” Mr Gediman said. “This was purely for safety’s sake.”

A sign announces a highway closure in Yosemite National Park
A sign announces a highway closure in Yosemite National Park (Noah Berger/AP)

Officials were quick to point out that Yosemite was not under imminent danger from the Ferguson Fire.

Authorities decided on the closure to allow crews to perform protective measures such as burning away brush along roads without having to deal with traffic in the park that welcomes four million visitors annually.

The last time the 7.5-mile-long valley was closed because of fire was 1990, he said.

Yosemite Valley is the centrepiece of the visitor experience, offering views of landmarks such as Half Dome, Sentinel Dome, Bridal Veil Fall, El Capitan and Yosemite Falls.

The glacial valley has been enveloped by a choking haze of smoke from the Ferguson Fire.

Flames from the Ferguson Fire burn near Yosemite National Park
Flames from the Ferguson Fire burn near Yosemite National Park (Noah Berger/AP)

Visitors are advised to “limit activity during the periods of poor air quality”, the park said in a statement. “Some facilities and services are closed or diminished.”

Over nearly two weeks, flames have churned through more than 57 square miles of timber in steep terrain of the Sierra Nevada just west of the park. The fire was just 25% contained on Tuesday.

Mandatory evacuations are in place in several communities while others have been told to get ready to leave if necessary.

More than 3,300 firefighters are working the fire, aided by 16 helicopters. One firefighter was killed on July 14, and six others have been injured.

Rhonda Salisbury, chief executive of Visit Yosemite/Madera County, said the regional visitors bureau has been relocating tourists statewide after the closure.