US based Jack Phillips from Masterpiece Cakeshop said it went against his faith to provide the cake back in 2012.
Judges at the court ruled 7 to 2 in his favour.
They said the Colorado Civil Rights Commission, who took the case against Phillips, showed hostility to religion.
The judges added that the rights of Jack Phillips had been violated under the first amendment.
Phillips was supported in the legal action by religious freedom group Alliance Defending Freedom.
Speaking after the verdict was announced on Monday, ADF Senior Counsel Kristen Waggoner said: "Jack serves all customers; he simply declines to express messages or celebrate events that violate his deeply held beliefs.
"Creative professionals who serve all people should be free to create art consistent with their convictions without the threat of government punishment. Government hostility toward people of faith has no place in our society, yet the state of Colorado was openly antagonistic toward Jack's religious beliefs about marriage.
"The court was right to condemn that. Tolerance and respect for good-faith differences of opinion are essential in a society like ours. This decision makes clear that the government must respect Jack's beliefs about marriage.
In a similar case in the UK, Ashers Bakery is currently awaiting a verdict in its appeal against a court ruling which said it was wrong to refuse to make a cake with a pro-gay marriage statement.
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.