President Uhuru Kenyatta visited Somalia and patted Kenya Defence Forces soldiers on the back for their efforts in fighting terrorist group Al-Shabaab in order to encourage security in the region.
Mr Kenyatta, dressed in military fatigue, met the troops serving under the African Union Mission in Somalia at Dhobley Military Camp.
President Kenyatta hoped to lift the soldiers' morale.
He has been to Mogadishu in the past on other state engagements.
"Your being here in Somalia has saved many lives, and for that Kenyans will forever be indebted to you. Your presence here has at least freed people of the fear of Al-Shabaab," he said.
"We have revived our tourism sector thanks to you for securing our country."
The Dhobley Military Camp is the headquarters of Amisom, a nerve centre and a log base for the UN.
The Head of State assured the soldiers that the government will always support and stand by them.
“We are talking to the new Somali government to emphasize to them the importance of building their military so that you can go back home. That is our exit strategy,” he added.
The visit came a few days after the State of the Nation address in which President Kenyatta paid glowing tribute to security personnel for their commitment and dedication in serving the country.
“In defence of our motherland, and in fulfilling our international obligations to pursue peace and security, we have lost some of our gallant soldiers,” President Kenyatta said in his State of the Nation address.
He added: “These losses remind us of the threat that is upon us. I stand here today to say that these gallant sons and daughters of Kenya have not fallen in vain. Their sacrifice for our freedom strengthens our resolve.”
Mr Kenyatta spent the day hearing first-hand accounts of how the troops are working.
He had lunch with them and also examined the equipment they are using in the war against Shabaab.
Since coming to office, the President has committed heavy investment in men and equipment as part of his campaign to ensure that Kenya has enough resources to secure itself.
Chief of Defence Forces Gen Samson Mwathethe – who accompanied President Kenyatta – said there is no better way for a Head of State to motivate a soldier than to spend time with him in a warzone.
“Your visit here today as the Commander-in-Chief has boosted the morale of these soldiers,” Gen Mwathethe said.
He expressed optimism that the new Somali administration will help facilitate harmony within and without.