A four-year-old boy was rescued after a half-hour ordeal of dangling through the security grille of a fifth-floor balcony.