A spokeswoman for the Centrepoint charity, of which the princess is patron, said: "It was the first time William and Harry had been to a hostel for the homeless, although William has visited a day-centre in the past. The visit was private.
"They were here over an hour and chatted very naturally with the other youngsters. They appear to be very mature for their age and are obviously very caring and concerned."
The Princess wants William, 13, a pupil at Eton, and Harry, 11, to see the other side of life in preparation for their future roles. It is understood it was her decision to bring her sons on the visit.
Staff had been told to expect the boys but the homeless youngsters were treated to a surprise.
The charity's spokeswoman said: "They were very excited when they saw the princes and were surprised at how natural they were. They listened and asked questions. They heard how some had come to be in the shelter and talked to them about their hopes for the future.
Last month, the princess was criticised over a speech she made at the charity's annual meeting, in which she was said to have taken too political a stand over the homeless. But she is reported to be keen to show the princes how other, less fortunate, youngsters are forced to live after running away from home.
The visit came shortly after the princes returned from a skiing holiday with their father. It was also a chance for the princess to put her own troubles to one side.
Only 24 hours before, she had been photographed in the street in tears after leaving the London home of a psychotherapist as pressure over the royal divorce grew.
The Princess has been under pressure to reply to a letter sent by the Queen late last year urging her to agree to an early divorce.
But the Princess of Wales, who is reported to be seeking a pounds 15m settlement, has not yet agreed to end the marriage. She is soon due to have her second meeting with her lawyer, Anthony Julius, to continue discussions on how to respond to the Queen.