Harrison Ford could have been killed when he was crushed by a hydraulic door on the set of the Millennium Falcon spaceship while filming the most recent Star Wars film, a court has heard.

Ford was reprising his role as Han Solo in Star Wars: The Force Awakens in June 2014 when he was knocked to the ground and crushed beneath the heavy door of the Millennium Falcon while filming at Pinewood Studios in London.

The company responsible, Foodles Production, pleaded guilty to two breaches under health and safety legislation.

The 71-year-old actor sustained severe injuries from the accident, including a broken left leg, after he walked on to the set not believing it to be live.

However, Milton Keynes magistrates court heard how the hydraulic spaceship door was operated by another person and that as the actor passed beneath it, he was hit hard in the pelvis and pinned to the floor. Ford was then airlifted to hospital in Oxford.

Andrew Marshall, prosecuting, said the breaches had caused a “risk of death” and that if the emergency stop had not been pressed in time, it could have been a very different outcome for Ford. “It could have killed somebody. The fact that it didn’t was because an emergency stop was activated,” he said.

A health and safety executive described the weight of the Millennium Falcon door as comparable to that of a small car.

Speaking about the injury to talk-show host Jonathan Ross in December, Ford said the hydraulics involved in the Millennium Falcon had considerably developed since 1977 when the doors were controlled with a pulley operated by hand.

Ford said: “Now we had lots of money and technology and so they built a fucking great hydraulic door which closed at light speed and somebody said, ‘Ooh I wonder what this is?’

“And the door came down and hit me on my left hip because I was turned to my right. And then it flung my left leg up and it dislocated my ankle and as it drove me down to the floor, my legs slapped on the ramp up to the Millennium Falcon and broke both bones in my left leg.”

Foodles pleaded guilty to one count under section two of the Health and Safety at Work Act 1974, which related to a breach of duty in relation to employees, and a second under section three, a breach over people not employed by the company.

Angus Withington, defending, said that while Foodles pleaded guilty, it would contest the level of risk involved.

The Health and Safety Executive (HSE) welcomed the guilty plea but said it had been a foreseeable incident. A spokesman said: “The British film industry has a world-renowned reputation for making exceptional films. Managing on-set risks in a sensible and proportionate way for all actors and staff – regardless of their celebrity status – is vital to protecting both on-screen and off-screen talent, as well as protecting the reputation of the industry.”

Foodles, which is owned by Disney, is due to be sentenced on 22 August at Aylesbury crown court. A spokeswoman said the company had cooperated fully with the HSE investigation. “The safety of our cast and crew was always a top priority throughout the production,” it said.

Ford recovered from the injuries in time to complete his portrayal of Han Solo in the film, which was set 30 years after the events in 1983’s Return of the Jedi and directed to much critical acclaim by JJ Abrams. It was the most successful film ever at the UK box office and has taken more than $2bn (£1.5bn) worldwide.

Abrams later spoke about how much Ford’s injury had “bonded” the crew on set and said when the actor had returned he was “better and stronger than ever, I can’t overstate that. There was a fire in his eyes that you see in the movie.”

Production of Star Wars: Episode VIII has got under way at Pinewood and the film is due for release in December 2017.