Twenty-one people, mostly firefighters, were injured in the fire, which sparked overnight in the mountainous region of the Sintra-Cascais Natural Park and was fanned by violent winds.
The gusts have since subsided, providing a “favourable” climate to put out the fire, Paulo Santos of the civil protection agency told local media.
He said emergency services and six fire-fighting planes would remain in the area to limit the risks of the blaze picking up again.
Prime Minister Antonio Costa hailed the operation’s success in the face of a “real threat”.
Authorities earlier evacuated 47 people as a precaution from a camping ground nearby.
Sintra was recognised as a World Heritage site by Unesco in 1995 for its cultural landscape, which combines parks and buildings that date from several centuries of Portuguese history.
Meteorological authorities had issued a warning in recent days over high temperatures.
Portugal has suffered a series of deadly fires, with massive blazes in 2017 leaving scores dead and prompting the government to introduce a variety of safety measures and launch an ambitious reforestation project.
The number of fires in Portugal has significantly reduced this summer, with burned areas down 60% compared to the average over the last 10 years, according the Institute of Conservation Nature and Forests.