The UK government has said it would consider taking a stake in any rescue operation for the firm's loss-making UK businesses, which are up for sale.
Stuart Wilkie, Tata Steel UK's director at Port Talbot and Llanwern, is working on plans for a management buyout.
Downing Street said the government was doing all it could to secure a "sustainable future" for the plant.
Confirming the short-notice visit earlier, a spokeswoman said Mr Cameron would be having meetings with Tata management, staff and union leaders.
"It is an opportunity for the prime minister to hear first-hand their views and discuss the way forward," she added.
Welsh Secretary Alun Cairns also attended, but not Business Secretary Sajid Javid, the spokeswoman confirmed.
Although it was Mr Cameron's first visit to the plant since the sale plans were announced in March, she said he had been involved in top-level discussions over its future.
"The government has been very focused over the last few weeks on making sure it is doing all it can to support a sustainable future for the steel industry in Port Talbot," she said.
"As the Prime Minister has said throughout, we want to do all we can to support a sustainable future for the steel industry in Port Talbot, but we don't underestimate the challenges facing the UK steel industry."
David Cameron later visited a car parts firm in Gorseinon, Gower.
A spokesman for First Minister Carwyn Jones said he was "surprised and disappointed" to learn of Mr Cameron's visit via Twitter.
The spokesman said: "We had invited him to Port Talbot previously, and indeed after various discussions and meetings the first minister had undertaken on steel yesterday had asked for a meeting with the prime minister today.
"However, his office said he was unavailable.
"We've said throughout that we are willing to put our political differences aside in the interests of our steel industry, but it does require respect from all parties to make this work."
David Cameron has visited Tata Steel management and unions in Port Talbot to discuss the crisis in the industry.