A lower court ruled the decision of family-run Ashers not to bake the product iced with the slogan Support Gay Marriage in 2014 was discriminatory after a legal challenge supported by Northern Ireland's Equality Commission.
The order was placed at its Belfast shop by gay rights activist Gareth Lee. Bakery owners Daniel and Amy McArthur have said the law risked "extinguishing" their consciences.
David Scoffield QC, for Ashers, said: "This is a case of forced or compelled speech, unlike other cases which have come before the court."
He added: "Mr and Mrs McArthur have been penalised by the state in the form of the judgment at the County Court for failing through their family company to create and provide a product bearing an explicit slogan 'Support Gay Marriage' to which they have a genuine objection in conscience."
Beforehand Mr McArthur, general manager of Ashers, said: "The Equality Commission has pushed for an interpretation of the law which extinguishes our conscience.
"They think that some people are more equal than others."
Mr McArthur said he should enjoy a basic right to live by his beliefs.
"But some people want the law to make us support something with which we disagree."
The case against Ashers was taken by Mr Lee with support from Northern Ireland's
Controversy first flared when Mr Lee, a member of the LGBT advocacy group Queer Space, ordered a cake featuring Sesame Street puppets Bert and Ernie for a private function marking International Day Against Homophobia.
His order was accepted and he paid in full but, two days later, the company called to say it could not proceed due to the message requested.
In the original court case, District Judge Isobel Brownlie ruled that religious beliefs could not dictate the law and ordered the firm to pay damages of £500.
Mounting an unsuccessful challenge at the Court of Appeal in Belfast in 2016, Ashers contended that it never had an issue with Mr Lee's sexuality, rather the message he was seeking to put on the cake.
On Tuesday Mr Scoffield said the case, a simple transaction, raised an issue of principle since those with deeply-held religious or philosophical convictions could be compelled to act against their beliefs.
He added: "The result of the approach taken by the district judge and Court of Appeal... is that someone providing bespoke goods must provide goods at the request of the customer, provided that is not unlawful - however offensive."
He said the McArthur family were being forced to use their skills, trade and experience for a purpose inconsistent with their beliefs and claimed they must "choose between operating their businesses or living and acting in accordance with their religious beliefs, and we say that cannot be the law".
Stay up to date with the latest news stories from a Christian perspective. Sign up to our daily newsletter and receive more stories like this straight to your inbox every morning.