The attack took place near Kabul, according to an Afghan interior ministry official, adding they believed the insurgent Taliban were behind it.
A spokesman for the militants said they had nothing to do with the attack.
The UN's mission to Afghanistan said in a statement on Twitter that "the UN family in Afghanistan mourns the loss of five Afghan...personnel in an incident today."
Attacks on international forces and foreign players have been rare since the Taliban signed a troop withdrawal deal with Washington almost a year ago.
However, violence against Afghans has escalated around the nation even as the Taliban and the Afghan government hold peace talks in Qatar.
On Thursday, three back-to-back blasts in eastern Kunar province left three people dead and two injured, according to a police spokesman.
At least two people were killed and five others injured in three separate blasts in eastern Nangarhar province, local officials said.
Unknown gunmen shot and injured Qotbuddin Kohi, a journalist working for Pajhwok News agency in northern Faryab province on Thursday, according to the media outlet's director.
Almost daily deadly attacks with small, magnetic bombs attached to the undercarriages of vehicles, as well as roadside explosive devices and shootings, are unnerving Afghan officials, activists and journalists.
Officials say that peace talks have largely stalled as the violence rises and US President Joe Biden's administration reviews how to handle the peace process.