Prime Minister Pedro Sánchez said the curfew, between the hours of 23:00 and 06:00, would come into force on Sunday, BBC reported.
Under the emergency measures, local authorities can also ban travel between regions, Mr Sánchez said.
He said he would ask parliament to extend the new rules, initially in force for 15 days, to six months.
Spain was hit hard during the first wave of the pandemic earlier this year and imposed a much more restrictive lockdown – one of the toughest in the world.
Like many other European regions, however, it has been hit by a second wave of infections.
In Italy, new restrictions were also announced on Sunday. The government said the steady rise in cases there was causing a huge strain on the country’s health services.
Meanwhile France has reported a record number of daily infections. A total of 52,010 infections were reported in the last 24 hours, up from just over 45,000 on Saturday.
What are Spain’s emergency measures?
Mr Sánchez said different regions would have up to an hour of flexibility if they wanted to modify the duration of the overnight curfew.
Restrictions on movement between districts would be determined by regional leaders and was likely to be dependent on work and medical needs, he added.
The new measures announced include a limit on public and private gatherings of different households to a maximum of six people.
“The situation we are going through is extreme,” Mr Sánchez said in a televised address on Sunday, adding: “It is the most serious in the past half century.”
More than half of Spain’s 17 regions had been calling for tighter restrictions, and the latest measures will apply to all regions except the Canary Islands.
The same level of emergency was introduced during the first wave of the pandemic in April.
Spain has passed one million cases since it began and nearly 35,000 people have died.
What is Italy doing to curb infections?
Italy is shutting cinemas, swimming pools, theatres and gyms from Monday.
Bars, restaurants and cafes will have to stop table service by 18:00. But shops and the majority of businesses will remain operating.
Italy’s measures were agreed between Prime Minister Giuseppe Conte and regional leaders.
“We think that we will suffer a bit this month but by gritting our teeth with these restrictions, we’ll be able to breathe again in December,” Mr Conte told a news conference on Sunday.
The prime minister has said he does not want to repeat the national lockdown imposed during the first wave in March and April because of the economic damage caused.
Under the new measures, the bulk of secondary school teaching will be conducted online instead of in the classroom.
The Italian move comes amid demonstrations in Naples, and then Rome, against stricter coronavirus measures, including curfews announced last week.
Sunday saw a new daily record of cases in Italy of more than 21,200. The number of deaths was 128.