Two babies and 12 mothers and nurses have been killed in a militant attack on a hospital in the Afghan capital Kabul.
Another 15 people, including a number of children, were injured in the attack by several gunmen, officials said.
Meanwhile, in the east, a bombing at a funeral killed at least 24 people.
In the wake of the attacks, President Ashraf Ghani said he was ordering the resumption of offensive operations against the Taliban and other groups.
He accused the militants of ignoring repeated calls for a reduction in violence.
The Islamic State (IS) group said it was behind the attack on a police commander's funeral in Nangarhar, in the east of the country. It is still not clear who carried out the attack on the hospital, and the Taliban have denied any involvement.
A maternity ward in the hospital is run by the international medical charity Medicins Sans Frontieres (MSF) and some of those working there are foreigners.
US Secretary of State Mike Pompeo called the attack on the hospital "sheer evil" and an "unconscionable assault". In a statement he urged the Afghan government and the Taliban to co-operate to "bring the perpetrators to justice".
What happened at the hospital?
The attack began at about 10am (local time) and locals described hearing two blasts then gunfire. One doctor who fled during the assault told the BBC about 140 people were in the hospital when the gunmen attacked.
Another doctor told AFP news agency that "total panic" took hold as the assault unfolded.
Ramazan Ali, a vendor who saw the attack begin, told Reuters news agency: "The attackers were shooting at anyone in this hospital without any reason... It's a government hospital, and a lot of people bring in their women and children for treatment."
Afghan special forces rescued 100 women and children, including three foreigners, an official told the BBC. The attackers, who reportedly had gained access dressed as police officers, were all killed by security personnel after a battle lasting hours.
Images from the scene showed soldiers carrying one newborn baby to safety, swaddled in a blood-stained blanket.
Many foreign staff live in a guesthouse behind the Dasht-e-Barchi Hospital and a doctor who fled the building told the BBC he saw an explosion there too.
In the past, similar attacks in this mostly Shia area of the capital have been attributed to IS. The group's leader in South Asia and the Far East was arrested in Kabul on Tuesday, with two other high profile members, Afghan intelligence said.
In 2017, IS gunmen disguised as medical staff attacked Kabul's main military hospital, prompting widespread shock and anger and raising questions about security. The authorities later confirmed about 50 people had been killed.
But the Taliban also attack hospitals. Last September, 20 people died after a truck packed with explosives was detonated by militants from the group outside a hospital in southern Zabul province.
On TV, Ghani said: "In order to provide security for public places and to thwart attacks and threats from the Taliban and other terrorist groups, I'm ordering Afghan security forces to switch from an active defence mode to an offensive one and to resume their operations against the enemies."
What happened at the funeral?
According to survivors, thousands of people had gathered for the local police commander's funeral, and the bomb detonated about half-way through. Ataullah Khogyani, a spokesman for the governor, said 68 people were injured.
A member of the provincial council was among the at least 24 killed.
Tuesday's attacks were widely condemned by countries around the world and human rights groups, with Amnesty International saying: "The unconscionable war crimes in Afghanistan today... must awaken the world to the horrors civilians continue to face."
On Twitter, UK Foreign Secretary Dominic Raab said: "I'm horrified by the appalling terrorist attacks in Afghanistan today - including on a maternity hospital. Targeting mothers, their newborns and medical staff is despicable."