Fifty people had been evacuated from the block, while two others on the first floor left the building with assistance from crews after concerns about the stability of the roof.
No-one needed hospital treatment after the fire, London Ambulance Service said.
The London Fire Brigade said 15 engines were at the scene in Inglewood Road, West Hampstead, after being called at just after 1am on Thursday.
Pictures posted on social media showed the blaze visible for miles. There are currently no reports of any injuries.
Station Manager Clainton Murray said: "Due to concerns that the roof could collapse inward, firefighters evacuated residents from the top floor.
"In addition fire crews assisted two people from the first floor and a number of other residents self evacuated from lower floors. Around 50 residents are using a local public house as a rest centre.
"The fire is also affecting the roof and in the early stages was very visible for miles around."
The fire is believed to have started in a flat on the fourth floor.