A wildfire burned dangerously close to homes at the foot of the rugged San Gabriel Mountains early Monday, but firefighters stood their ground and turned the flames back.

The dramatic battle came on the third day of a 538-acre blaze that forced at least 1,000 people from homes in and near Santa Anita Canyon in the foothill suburb northeast of Los Angeles. By late Monday most had been allowed to return to their homes, while evacuation orders remained in effect for about 300 people.

• Click here for photos.

Mayor Kurt Zimmerman was emotional as he recounted how the firefighters saved homes.

"Early this morning the flames had raced to within a couple feet of our homes in the canyon and those brave firefighters ... formed a perimeter with their bodies and their fire engines," he told a press conference. "It was a barricade of steel and water and human flesh and blood and they stopped the fire dead in its tracks."

The fire's overnight advance reduced containment from 30 percent to 21 percent, but by Monday evening little smoke wafted from the charred slopes. The burn area, however, was not expected to be fully surrounded by fire lines for four to seven days.

All the city's schools were closed Monday, but were expected to be open again on Tuesday.

The cause of the fire remained under investigation.

On the Scene: Fox News' Adam Housley Covers Fires in Sierra Madre.

The fire erupted Saturday afternoon in a popular hiking area as unseasonable extreme heat and low humidity set in over Southern California. By late that night it was a bright orange line descending like slow-moving lava down the steep mountainside, triggering evacuations along the interface between the city and wilderness.

Helicopters and airplanes bombarded the fire with water and retardant drops Monday while firefighters labored in temperatures in the 90s for a third day. Nearly 700 firefighters were on the lines.

"It's a hot day and these are steep slopes," said Sierra Madre fire spokeswoman Barbara Croonquist. "And the fact that it's so near the city makes it hard."

Weather was forecast to begin improving Tuesday, with the onset of a widespread cooling trend.

Four firefighters had minor injuries — a bee sting, a strained knee, and two cases of heat exhaustion, authorities said. A small outbuilding was destroyed.

Investigators were working to determine the cause of the fire.

The blaze stranded 50 guests from a wedding party at the Chantry Flats ranger station on Saturday until they were airlifted out Sunday afternoon. It took five helicopter trips from the ranger station to the parking area where the wedding party's cars were parked. The party then was escorted out by road.

Sierra Madre is about 15 miles northeast of downtown Los Angeles, located on the edge of Angeles National Forest. A tight-knit community of about 11,000 residents, Sierra Madre is famous as the setting of the 1956 science fiction classic "Invasion of the Body Snatchers."

Air quality regulators on Monday urged people in the San Gabriel Valley area of Los Angeles County to avoid unnecessary outdoor activities because of smoke from the Sierra Madre wildfire.

To the south in San Diego County, firefighters fully contained a fire that burned 100 acres of thick brush on the edge of Los Penasquitos Canyon Preserve. The cause of the fire was being investigated, but it did not appear to be arson, fire spokesman Maurice Luque said.

The Federal Emergency Management Agency said it has authorized funds to reimburse the state for eligible Sierra Madre firefighting costs exceeding $2.1 million.