Abas Abdullahi Siraji was in his car near the presidential palace in Mogadishu when he was killed by Ahmed Abdullahi Abdi, who reportedly mistook him for a militant Islamist.
The minister's death caused shock and anger at the time.
The military court which sentenced the soldier said he can appeal.
His lawyers argued that the killing was an accident, the AFP news agency reports.
They said that the minister's car attracted suspicion after it drove up behind the car carrying the auditor general, who the soldier was protecting.
At 31, Mr Siraji became Somalia's youngest-ever member of parliament last November before becoming the minister of public works earlier this year.
He grew up as a refugee in neighbouring Kenya, home to hundreds of thousands of Somalis who fled drought and conflict, and was seen a role model for his widely admired determination to succeed.
Sensing his popularity with the youth, President Mohamed Abdullahi Mohamed Farmajo appointed him to the cabinet.
When Mr Siraji was killed, the president cut short a visit to Ethiopia to attend his state funeral.
Somalia has been wracked by conflict since the long-serving ruler Siad Barre was ousted in 1991.
It is currently battling militant Islamists from the al-Shabab group, which is affiliated to al-Qaeda.
The Somali soldier who shot dead the country's youngest-ever cabinet minister last month has been sentenced to death by firing squad.