The high-profile dispute began in 2014 when the bakery refused to make a cake with the slogan "Support Gay Marriage". The customer, gay rights activist Gareth Lee, sued the company for discrimination on the grounds of sexual orientation and political beliefs. Ashers lost the case and the subsequent appeal, but on Wednesday the firm won its appeal at the Supreme Court.
In the court's judgement (case reference  UKSC 49), president of the Supreme Court Lady Hale ruled that the bakers did not refuse to fulfil the order because of his sexual orientation.
"They would have refused to make such a cake for any customer, irrespective of their sexual orientation," she said, "Their objection was to the message on the cake, not to the personal characteristics of Mr Lee."
"This conclusion is not in any way to diminish the need to protect gay people and people who support gay marriage from discrimination," said Lady Hale, "It is deeply humiliating, and an affront to human dignity, to deny someone a service because of that person's race, gender, disability, sexual orientation, religion or belief. But that is not what happened in this case."
The legal battle - which has lasted four-and-a-half years and has cost nearly £500,000 so far - has raised questions over equality and freedom of conscience.
The Equality Commission for Northern Ireland, which has supported Gareth Lee's action against Ashers, said it would study the implications of the judgement carefully. "There is a concern that this judgement may raise uncertainty about the application of equality law in the commercial sphere, both about what businesses can do and what customers may expect," said Dr Michael Wardlow, the organisation's chief commissioner.
Questions will now be asked as to whether the Equality Commission was right to spend more than £250,000 of public money on this case. Ashers bakery has spent more £200,000 on the case. It is being paid by The Christian Institute, a charity and lobby group. The cake at the centre of the dispute would have cost £36.50.
Some will regard the ruling - that service providers of any religion, race or sexual orientation can refuse to endorse a message they profoundly disagree with - as a victory for freedom of expression and freedom of ideas.
The ruling now poses the question whether it would it be lawful, for instance, for a bakery to refuse to make a bar mitzvah cake because the bakers owners disagreed with ideas at the heart of the Jewish religion? What about a cake promoting "the glory of Brexit", "support fox hunting", or "support veganism"?