Up to 70 personnel will join a United Nations contingent supporting African Union troops fighting al-Shabab.
Up to 300 could also be deployed in South Sudan over time.
The PM, who will pledge the support at the UN General Assembly summit, said the approach could help curb migrants coming to Europe.
Somalia’s President Hassan Sheikh Mohamoud is one of several world leaders with whom Mr Cameron will hold face-to-face talks.
Al-Shabab is battling Somalia’s government for control of the country.
British forces deployed there will provide combat training and medical, logistical and engineering support.
The role of those being sent to South Sudan will also include combat training as well as engineering work to strengthen vital infrastructure.
Conflict between forces loyal to President Salva Kiir and his former deputy Riek Machar has forced more than 2.2 million people from their homes in the state, which broke away from Sudan in 2011.
Mr Cameron said it was important to “step up” existing British contributions.
“Obviously we will want to see all the right force protection arrangements in place but we should be playing a part in this,” the PM said.
“The outcome in Somalia, if it’s a good outcome, that’s good for Britain,” he added.
“It means less terrorism, less migration, less piracy. Ditto in South Sudan: if we can, as peacekeepers, help to maintain order and peace and see stable development in that country then that is going to be, again, less poverty, less migration, less issues that affect us back at home.”
British troops will not be involved in combat roles, Mr Cameron said.
“It’s not committing troops to conflict, it’s committing troops to a UN blue-hatted peacekeeping role – as we’ve done many times in the past, as we will do in the future,” he told the BBC.
“And one of the reasons we’re doing it is obviously the expertise that British troops have in training, engineering, and mentoring and we’re raising the standard for peacekeeping troops which has had some issues and problems in the recent past.”