Brian Froud says that Labyrinth was first discussed between himself and director Jim Henson. Both agreed to work on another project together, and Froud suggested that the film should feature goblins. On the same journey, Froud "pictured a baby surrounded by goblins" and this strong visual image, along with Froud's insight that goblins traditionally steal babies, provided the basis for the film's plot.
Henson discussed the film's origins to say that he and Froud "wanted to do a lighter weight picture, with more of a sense of comedy since The Dark Crystal got kind of heavy, heavier than we had intended. Now, I wanted to do a film with the characters having more personality and interacting more."
Labyrinth was being seriously discussed as early as March 1983, when Henson held a meeting with Froud and children's author Dennis Lee. Lee was tasked with writing a novella on which a script could be based, submitting it at the end of 1983. Henson approached Terry Jones to write the film's script, as "his daughter Lisa had just read Erik the Viking and suggested that he try me as screenwriter". Jones was given Dennis Lee's novella to use as a basis for his script but later told Empire that Lee had produced an unfinished "poetic novella" that he "didn't really get on with". In light of this, Jones "discarded it and sat down with Brian [Froud]'s drawings and sifted through them and found the ones that I really liked, and started creating the story from them".
Jones is credited with writing the screenplay, while the shooting script was actually a collaborative effort that featured contributions from Henson, George Lucas, Laura Phillips, and Elaine May. Jones has said that the finished film differs greatly from his original vision. Jones states that, "I didn't feel that it was very much mine. I always felt it fell between two stories, Jim wanted it to be one thing and I wanted it to be about something else." Jones has said that his version of the script was "about the world, and about people who are more interested in manipulating the world than actually baring themselves at all". In Jones' original script, Jareth merely seems "all powerful to begin with" and is actually using the Labyrinth to "keep people from getting to his heart".
Jones has said that Bowie's involvement in the project had a significant impact on the direction taken with the film. Jones had originally intended for the audience not to see the centre of the Labyrinth, prior to Sarah's reaching it, as he felt that, in doing so, it robbed the film of a significant "hook". Henson decided that he wanted Jareth to sing and appear throughout the film, which was something Jones considered the "wrong" decision, with the thought of Bowie starring in the film in mind. Despite his misgivings, Jones rewrote the script to allow for performing songs throughout the film. This draft of the script "went away for about a year". During this time, it was redrafted first by Phillips and subsequently by Lucas.
An early draft of the script attributed to Jones and Phillips is markedly different from the finished film. The early script has Jareth enter Sarah's house in the guise of Robin Zakar, the author of a play she is due to perform in. Sarah does not wish her brother would be taken away by the goblins, and Jareth snatches him away against her will. Jareth is overtly villainous in this draft of the script. His final confrontation with Sarah tells her that he would "much rather have a Queen" than "a little goblin prince". The early script ends with Sarah kicking Jareth in disgust, and her blows transform him into a powerless, sniveling goblin. In the extensive junkyard scene, Jareth operates the Junk Lady as a puppet, whereas, in the film, she is autonomous. There is actually a pub or bar in the Labyrinth where the Man with Hat and Hoggle gather, and the river Lethe in Greek myth is mentioned. As well as this, the ballroom scene features extensive dialogue between Jareth and Sarah, whereas, in the film, there is none (though there is in the novelization by A. C. H. Smith), and the goings-on with the dancers in the ballroom are more overtly sexualised.
The redrafted script was sent to Bowie, who found that it lacked humour and considered withdrawing his involvement in the project as a result. To ensure Bowie's involvement, Henson asked Jones to "do a bit more" to the script to make it more humorous. May met with Henson in several months, prior to the start of filming in April 1985, and was asked to polish the script. May's changes "humanised the characters" and pleased Henson to the extent that they were incorporated into the film's shooting script.
At least 25 treatments and scripts were drafted for Labyrinth between 1983 and 1985. The film's shooting script was only ready shortly before filming began.