Abdurahman Sheikh Hassan, an Ethiopian, was found guilty of "participating in a terrorist organisation" earlier this week over alleged links to the Ogaden National Liberation Front (ONLF), an outlawed secessionist rebel group.
"Under the guise of his job, he has been passing information to a terrorist organisation with the aim to help them," Judge Mulugeta Kidane said, delivering the sentence.
Hassan appeared in court on Friday holding Muslim prayer beads.
He shook his lawyer's hand after she translated the sentence to him as Hassan does not speak Ethiopia's main language Amharic.
He was sentenced along with Sherif Badio, whom the charge sheet lists as a senior member of the ONLF. Badio was sentenced in absentia to life in prison for "serving as a leader or a decision maker in a terrorist organisation".
Hassan, the head of UN security in Ethiopia's troubled Ogaden region, was arrested last July after he helped to negotiate the release of two UN World Food Programme hostages.
According to the charge sheet, the hostages were kidnapped by members of the ONLF.
The judge said Hassan failed to prove he did not have links to the ONLF and said he was guilty of collaborating with Badio.
UN officials were not available for comment on Friday.
Mulugeta said the severity of the crimes called for "a high level of punishment", adding that Hassan was not given the maximum sentence for his charge - ten years in prison - since he has no prior criminal record.
The men were sentenced under Ethiopia's anti-terrorism legislation, which rights groups have criticised for being far-reaching and used to stifle peaceful dissent.
In December, two Swedish journalists were sentenced to 11 years in prison after an Ethiopian court found them guilty of supporting the ONLF in the Ogaden, a region that borders Somalia.
Twenty-four people, including prominent journalist Eskinder Nega and opposition member Andualem Arage, are currently on trial on charges of terrorism. Eskinder was arrested after publishing an article questioning arrests under the anti-terrorism legislation.
The verdict in that case, which has been twice delayed, is expected on Wednesday. The 24 could face the death penalty if found guilty.
ONLF militants have been fighting for independence from Addis Ababa since 1984, claiming they have been marginalised by the ruling government.
Recent oil and gas discoveries in Ogaden have brought hopes of wealth but also fresh fears of conflict.