BUCHAREST, Romania — All European Union countries must recognize same-sex marriage, at least in relation to immigration cases where one partner is a citizen of the bloc, its highest court ruled on Tuesday.

The verdict was an important victory for L.G.B.T. rights groups, which have long argued that same-sex spouses of European Union citizens should be afforded the same basic right to live and work across the bloc’s 28 countries as heterosexual spouses, regardless of individual countries’ stances on same-sex marriage.

It also highlighted growing tensions between the bloc’s core institutions and some of its newer, more socially conservative member states.

Six European Union countries — all of them former Eastern Bloc nations that joined the union in the 21st century — have yet to legalize same-sex marriages or civil unions. In a statement issued along with its verdict, the European Court of Justice in Luxembourg said they remained free not to do so.