Manmohan Singh asked the state government to ensure the rehabilitation of the thousands forced to flee their homes.
He also told reporters that he expected the security scenario to improve.
"People behind such ghastly violence would be punished and all help extended to the UP government."
While Manmohan Singh spoke to Divisional Commissioner Bhuvnesh Kumar and District Magistrate Kaushal Raj Sharma, Sonia Gandhi mingled with some women and sought to know the sequence of events.
Rahul Gandhi spoke to some youth.
He also asked Minister of State for Home Affairs R.P.N. Singh to take petitions from the people and address their issues.
Uttar Pradesh Governor B.L. Joshi and Uttar Pradesh Health Minister Ahmed Hasan accompanied the prime minister.