Speaking after talks with his Turkish counterpart in Ankara, the UK prime minister said Islamic State (IS) was a "common enemy" that must be confronted.
He hailed the countries' existing intelligence co-operation and said this would be stepped up further.
The US and EU want Turkey to take a more active role in tackling IS.
At a press conference in the capital, Turkey's prime minister Ahmet Davutoglu said the two countries shared a "strong and common political will" to address the threat posed by foreign fighters travelling to and from conflict zones in Syria and Iraq.
Mr Cameron said that British jihadists had "sometimes" passed through Turkey and the two men had had "productive discussions" over how they could be detained and, if possible, prosecuted.
The UK government is seeking greater powers to confiscate the passports of people returning to the UK from Iraq and Syria who are thought to pose a threat to national security, with Parliament currently debating changes to the law.
Asked whether Turkey could be doing more to identify and stop suspects at its borders, Mr Cameron said the two countries were already working "as closely as we possibly can" to tackle the threat.
He said: "Whether it is about stopping people coming through Turkey to Syria or Iraq to fight for Islamic State, whether it's about making sure we deal with people when they return, whether it is the highest levels of intelligence co-operation that we can possibly achieve between our countries, this is all about making sure people are safer in Turkey and making sure people are safer back home in the UK."
As well as addressing the "extremist ideology" that fuels Islamic State, he reiterated his calls for a transition to a more democratic and representative government in Syria and more efforts towards reconciliation by the new government in Baghdad.
Mr Cameron also hailed a growth in economic links between the UK and Turkey, saying bilateral trade had increased by 60% since 2010.
Making his first visit to Turkey since 2010, Mr Cameron will later be hosted at a dinner by president Recep Tayyip Erdogan.
Mr Cameron will not return to the UK in time for Prime Minister's Questions on Wednesday, with Liberal Democrat Deputy Prime Minister Nick Clegg expected to step in for him.

17 June 2016 Last updated at 18:05 BST
But during a ceremony to honour the victims, one policeman refused the shake hands with the president and his prime minister.
Interviewed on TF1 television afterwards, he said "There are too many problems in the police. We've had enough."

The 58-year-old spent three months in charge of the Addicks at the end of the 2013-14 campaign, keeping the club in the Championship.
Since leaving The Valley the Belgian has spent time in charge of Blackpool, Standard Liege and Metz.
Riga replaces compatriot Karel Fraeye, who was sacked from his post as interim head coach on Wednesday.
Charlton are currently 23rd in the Championship table, three points from safety, and are on a run of 10 games without a win in all competitions.
Fraeye was appointed in late October following the departure of Guy Luzon, but only won two of his 14 matches in charge of the first team.
In a statement on the club website, Addicks owner Roland Duchatelet admitted the club had made errors in player recruitment and said the board of directors accepted responsibility for "a disappointing season".
"It was crucial we dealt with the position of the head coach," the Belgian businessman added.
"Jose did an excellent job in his short period with Charlton two seasons ago. He was very popular with supporters and I believe that he will get us back on track."
Riga won seven of his 16 games during his stint at The Valley in 2014 but left the south-east London club when his contract was not renewed that summer and joined Blackpool.
BBC Radio London's Andy Rowley
Charlton fans are increasingly angry with how the club is being run by Roland Duchatelet, who is now onto his sixth head coach since taking over the club in January 2014.
There have been a number of recent protests at The Valley aimed at Duchatelet and chief executive Katrien Meire from supporters, who have now come together to form a group called "Coalition Against Roland Duchatelet" in an attempt to bring about a sale of the club.
Riga has far more managerial experience than his predecessor Karel Fraeye but, given his previous links to Duchatelet and the antipathy towards the board of directors, the appointment could only serve to fan the flames for further supporter unrest.
David Cameron has said the UK and Turkey are working "hand in glove" to prevent British jihadists returning home after fighting in Iraq and Syria.
[NEXT_CONCEPT]
French President Francois Hollande has vowed to improve the protection of police officers, after a police couple was killed by a militant this week.
[NEXT_CONCEPT]
Championship strugglers Charlton Athletic have reappointed Jose Riga as head coach on an 18-month deal.