MADRID — When the news came five years ago that Charles Wuorinen was writing an opera based on “Brokeback Mountain,” the 1997 Annie Proulx short story that was made into an Oscar-winning film in 2005, it seemed at first a baffling mismatch of composer and subject. Mr. Wuorinen, 75, built his reputation as and remains an unabashedly complex Modernist. “Brokeback Mountain” is the immensely sad tale of the impossible love between two Wyoming cowboys.

But over time, the idea of a Wuorinen adaptation of “Brokeback Mountain” grew more intriguing. One certainly did not want some sentimental score for this wrenching tragedy set in the rugged American West. The project seemed more promising still when it was announced that Ms. Proulx would be writing the libretto, her first effort in this genre.

The premiere of “Brokeback Mountain,” one of the most anticipated events of the international opera season, took place at the Teatro Real here on Tuesday night. It is a serious work, an impressive achievement. But it is a hard opera to love.

Mr. Wuorinen has written an intricate, vibrantly orchestrated and often brilliant score that conveys the oppressiveness of the forces that defeat these two men, whose lives we follow over 20 years, starting in 1963, when they take a summer job herding sheep on Brokeback Mountain. But the same qualities in Mr. Wuorinen’s music that can captivate listeners — ingenious complexity, lucid textures, tartly atonal harmonic writing — too often weigh down the drama in this work.