Ashers Baking Company, based in County Antrim, was taken to court by gay rights activist Gareth Lee.
A Belfast judge said, as a business, Ashers was not exempt from discrimination law.
Damages of £500 were agreed in advance by both legal teams.
A lawyer for Mr Lee said the money would be donated to charity.
The judge said Ashers is “conducting a business for profit”, it is not a religious group.
It was found to have discriminated against Mr Lee on the grounds of sexual orientation as well as his political beliefs.
The judge said she accepted that Ashers has “genuine and deeply held” religious views, but said the business was not above the law.
Mr Lee had claimed the bakery discriminated against him on the grounds of his sexual orientation.
Ashers said the slogan was against its Christian beliefs.
Speaking outside Belfast County Court ahead of Tuesday’s ruling, Ashers general manager Daniel McArthur said: “We happily serve everyone but we cannot promote a cause that goes against what the Bible says about marriage.
“We have tried to be guided in our actions by our Christian beliefs.”
A judge said as a business, Ashers was not exempt from discrimination law.
Reacting to the decision, Northern Ireland Deputy First Minister Martin McGuinness tweeted: “Ashers bakery judgement a good result for equality, gay people have for far too long been discriminated against. We and the law on their side.”
Michael Wardlow of the NI Equality Commission welcomed the judgement, which he said was “very robust and very clear”.
John O’Doherty, of gay rights group the Rainbow Project, said: “While sympathetic as some may be to the position in which the company finds itself, this does not change the facts of the case.
“The judge clearly articulated that this is direct discrimination for which there can be no justification.”
‘Utterly sickened’ of
However, DUP MLA Paul Givan, who has proposed that lawmakers in the Northern Ireland Assembly introduce a “conscience clause” as a result of the Ashers case, said many Christians would view the ruling as “an attack” on their religious convictions.
“What we cannot have is a hierarchy of rights, and today there’s a clear hierarchy being established that gay rights are more important than the rights of people to hold religious beliefs,” Mr Givan added.
Traditional Unionist Voice leader Jim Allister said it was “a dark day for justice and religious freedom in Northern Ireland”.
Gay marriage cake
Another bakery made the cake after the order was turned down by Ashers