The child was rescued by the fire brigade as flames swept through the ninth-floor flat. Stephen Waller, for the prosecution, said the boy had been left for two hours by his mother's boyfriend.
The man, 32, a mini-cab driver, denied cruelty to a child. He is alleged to have abandoned the boy in circumstances likely to cause him unnecessary suffering or injury to health.
Mr Waller said the boy was found by firemen in his bedroom in the flat in Stockwell, south London. The defendant, who cannot be named - to protect the identity of the boy - was expected to stay with the child on 23 September last year until the child's mother returned. The man claimed he had gone to buy food for the child, but the police found food in the flat.
The court heard that petrol appeared to have been poured through the letterbox and set on fire. Mr Waller said: 'There is no suggestion that this defendant started the fire.'
The case continues today.