Several hundred firefighters and 160 vehicles were dispatched late Saturday to tackle the blaze, which broke out in the afternoon in the municipality of Pedrogao Grande before spreading fast across several fronts.
"Unfortunately this seems to be the greatest tragedy we have seen in recent years in terms of forest fires," the visibly moved Prime Minister Antonio Costa said.
"The number of fatalities could still rise," he said at the Civil Protection headquarters near Lisbon.
"The priority now is to save those people who could still be in danger."
Portugal was sweltering under a severe heatwave Saturday, with temperatures exceeding 40 degrees Celsius (104 degrees Fahrenheit) in several regions.
Some 60 forest fires broke out across the country during the night, with around 1,700 firefighters battling to put them out.
Secretary of State for the Interior Jorge Gomes said 22 people burned to death in their cars when they found themselves trapped by flames on the road between Figueiro dos Vinhos and Castanheira de Pera.
Three others died from smoke inhalation.
Sixteen people were injured, including five firefighters. Two of those were seriously injured.
The flames spread "with great violence", moving out on four fronts, Gomes said.
A number of villages were affected by the main fire and evacuation procedures had been put in place for some of them, Costa added. Officials were not immediately able to comment on the extent of the damage.
Spain dispatched two water-bombing planes today in the morning to aid the Portuguese fire service on the ground, the prime minister said.
Costa said a period of national mourning would be announced shortly.
President Marcelo Rebelo went to the Leiria region to meet families of the victims, "sharing their pain in the name of all the Portuguese people," he said.
Firefighters did "all they could" when faced with the blaze, he added.
Dozens of people who fled their homes were taken in by residents of the nearby municipality of Ansiao.
"There are people who arrived saying they didn't want to die in their homes, which were surrounded by flames," Ricardo Tristao of Ansiao told reporters.
Portugal was hit by a series of fires last year which devastated more than 100,000 hectares (1,000 square kilometres) of the mainland.
Fires on the tourist island of Madeira in August killed three people, while over the course of 2016 around 40 homes were destroyed and 5,400 hectares of land burned.