The federal government had challenged the validity of the Australian Capital Territory's law that had allowed gay marriages in the nation's capital and its surrounding area, starting last Saturday.
The federal government's lawyer argued that having different marriage laws in various Australian states and territories would create confusion.
The ACT, which passed the law in October, said it should stand because it governs couples outside the federal definition of marriage as being between members of the opposite sex.
The High Court unanimously ruled that the ACT's law could not operate concurrently with the federal Marriage Act, which was amended in 2004 to define marriage as between a man and a woman.
The court said in a statement: "The Marriage Act does not now provide for the formation or recognition of marriage between same sex-couples. The Marriage Act provides that a marriage can be solemnised in Australia only between a man and a woman. That Act is a comprehensive and exhaustive statement of the law of marriage."
For Ivan Hinton, who married his partner Chris Teoh on Saturday, the result was heartbreaking. The couple received their marriage certificate yesterday and immediately applied to change their surnames to Hinton-Teoh. Mr Hinton said he does not regret going through with the wedding and will always consider Mr Teoh his husband.
"This was an unprecedented and historic opportunity," he said. "I wouldn't have missed it for the world."
Rodney Croome, national director of the advocacy group Australian Marriage Equality, said his group knows of about 30 same-sex couples who had married since Saturday, although the actual number may be slightly higher.
The ruling means their marriages are nullified.
Outside the court in Canberra, a tearful Mr Croome, flanked by several same-sex couples who were married in the past week, said the ruling was a defeat for marriage equality but there had been a greater victory this week.
"That victory was the nation saw for the first time, I believe, what is really at the core of this issue - they've seen that marriage equality is not about protest or politics or even about laws in the constitution, ultimately. Marriage equality is about love, commitment, family and fairness," Mr Croome said.
Lyle Shelton, managing director of Australian Christian Lobby, which opposes same-sex marriage, praised the court ruling and said common sense had prevailed.
As for the ruling's impact on the newly wedded couples, Mr Shelton said it was "really sad that they were put in a position" in which they were allowed to marry before the court handed down its judgment.
"But I guess they knew as they went into these arrangements that the decision may not go their way," he said.
Prime minister Tony Abbott opposes gay marriage and his coalition blocked two federal bills last year that would have allowed legal recognition of same-sex partnerships.
The ruling comes a day after India's Supreme Court struck down a 2009 lower court decision to decriminalise homosexuality, dealing a blow to gay activists who have fought for years for the chance to live openly in India's deeply conservative society.
Gay marriage has legal recognition in 18 countries as well as 16 US states plus the District of Columbia.