The court said that the dismissal of Carole Webb, 25, a clerk, by EMO Air Cargo, violated EU principles on the equal treatment of men and women at work.
Its decision may now open the way for her to claim compensation against her former employer.
Mrs Webb, of West Drayton in west London, was sacked in 1987 two weeks after joining the firm having being taken on to replace another woman who was about to start maternity leave.
Kamlesh Bahl, chairwoman of the Equal Opportunities Commission, said the ruling would have far-reaching implications for companies, which would have to look again at the way they treated pregnant women. 'The EOC has a long-term aim of securing a fairer deal for pregnant women in the workplace and this case will contribute significantly to achieving that aim,' she said.
'It will have major implications for employers, who will need to change their employment culture and practices and follow the lead of those progressive employers who already recognise the valuable contribution women make in the workplace and the economy.'
Mrs Webb, who now has two children, began her seven-year legal battle by taking her case to an industrial tribunal - with the help of the Hillingdon Legal Resource Centre in west London. Although she lost, she appealed to the Employment Appeal Tribunal. When she lost there, she took her case to the Court of Appeal.
Although she lost again at the Court of Appeal, she was given leave to appeal to the House of Lords, which referred her case to the European Court of Justice.
The case will now go back to the Lords so that peers can consider it in the light of yesterday's ruling.
Mrs Webb told the BBC One O'Clock News yesterday: 'I am very pleased and very relieved. I have waited a long time - seven years - but it is going to give women the right to take companies to court.'
The ruling was also welcomed by John Monks, the TUC general secretary. 'Employers will now have to accept that pregnancy is a normal part of women's lives and that they can't use pregnancy as an excuse for treating women any differently to men when they take personnel decisions,' he said.
Michael Forsyth, the employment minister, said he did not think the ruling would have wider implications for British women as they were already protected by legislation passed last year.
He told BBC Radio: 'The 1993 legislation already makes it automatically unfair to dismiss a woman on grounds of pregnancy, or even to select a woman for
redundancy because of pregnancy. That now applies to every woman who is pregnant and whose child is expected after 16 October this year.'