Gilbert Baker, creator of the gay pride rainbow flag, is shown in Stockholm in 2003. (Fredrik Persson/European Pressphoto Agency)

On June 30, 2015, when the White House was transformed by outdoor lighting into a representation of the rainbow, people instantly grasped its significance. It was four days after the Supreme Court’s landmark decision guaranteeing gay couples the right to marry.

The Empire State Building was similarly bathed in rainbow hues, and Niagara Falls was transformed into a cascade of color. More than 25 million people changed their Facebook profile photos to reflect the universal symbol of gay pride.

The rainbow flag that unfurled over a movement and, in many ways, gave it definition and a public identity was the creation of one man, Gilbert Baker.

He designed and sewed the first rainbow flag for a San Francisco gay rights rally in 1978. Mr. Baker, who playfully called himself the Betsy Ross of gay liberation, was found dead March 31 at his apartment in New York City. He was 65.

A spokeswoman for the New York City medical examiner’s office said the cause was heart disease.

Mr. Baker at the Museum of Modern Art in New York City in 2016. (Spencer Platt/Getty Images)

After serving as an Army medic and nurse, Mr. Baker settled in San Francisco in 1972 and soon became active in the city’s gay rights movement. One of the first things he bought was a sewing machine, which he used to make his own clothing — including gowns he wore in occasional appearances as a drag queen.

“Because I loved to sew, my role in the movement became to make banners,” Mr. Baker told the Refinery29 website in 2015. “That’s really how I ended up making the first flag — I was the guy who could sew it.”

He became friends with Harvey Milk, a member of San Francisco’s Board of Supervisors and one of the country’s first openly gay elected officials. Milk suggested to Mr. Baker that the gay community needed some kind of recognizable emblem of empowerment.

“I decided that we should have a flag,” Mr. Baker said in a 2015 interview with the Museum of Modern Art, “that we are a people, a tribe if you will. And flags are about proclaiming power, so it’s very appropriate.”

Inspired in part by the U.S. flag, he developed a design of eight brightly colored horizontal stripes: from top to bottom, pink, red, orange, yellow, green, turquoise, indigo and violet.

“The rainbow is so perfect because it really fits our diversity in terms of race, gender, ages, all of those things,” he said in the interview with MoMA, which has included his flag in its design collection. “Plus, it’s a natural flag — it’s from the sky!”

With a team of 30 volunteers, Mr. Baker soaked strips of cotton muslin in trash cans filled with dye. He then stitched the pieces together to create the first rainbow flag, which measured 30-by-60 feet. It was raised on June 25, 1978.

The 1 1/4-mile-long rainbow flag designed by Mr. Baker in Key West, Fla., in 2003. (Andy Newman/European Pressphoto Agency)

“When it went up and the wind finally took it out of my hands, it blew my mind,” Mr. Baker told CNN two years ago. “I saw immediately how everyone around me owned that flag. I thought: It’s better than I ever dreamed.”

Because it was hard to obtain pink and turquoise fabric, Mr. Baker soon altered the flag, eliminating pink altogether and blending turquoise and indigo into a single shade of blue. The most widely used form of the flag now consists of six colors.

The rainbow flag was tantamount to a declaration of independence, a vivid public symbol that gay people would no longer be invisible.

For that reason, the flag also became a divisive force in the nation’s legal and cultural wars. People went to court to win the right to display it in public.

In November 1978, five months after Mr. Baker’s first flag was flown, Milk and San Francisco Mayor George Moscone were assassinated. Mr. Baker, who lost many friends to HIV and AIDS, became an increasingly outspoken advocate for gay rights.

Over time, Mr. Baker’s flag — like the gay rights movement itself — became more widely accepted. Because Mr. Baker did not patent his design, he did not profit from its countless commercial adaptations.

Instead, he worked for a San Francisco flag company for several years and later became a freelance designer, creating banners and flags for visiting heads of state, the Democratic National Convention and the Super Bowl.

In 1994, Mr. Baker moved to New York, where he created a mile-long rainbow flag that was paraded through the streets on the 25th anniversary of the Stonewall riots, which are considered the beginning of the modern gay rights movement.

Eleven years later, in Key West, Fla., Mr. Baker made an even larger flag, stretching a mile and a quarter across the island city from the Atlantic Ocean to the Straits of Florida.

“He was a genius at political theater, at political art,” Jeff Sheehy, a city supervisor, told the San Francisco Chronicle. “He’s one of these heroes who never sought attention for himself. But he was relentless.”

Gilbert Baker was born June 2, 1951, in Chanute, Kan., and graduated from high school in Parsons, Kan. His father was a lawyer and judge, his mother a teacher. They didn’t speak to their son for years after he told them he was gay.

During his Army service, Mr. Baker cared for wounded soldiers from the Vietnam War at a military hospital in San Francisco.

His harrowing experiences in the Army, where he was often disparaged by drill sergeants and fellow soldiers, were described in Randy Shilts’s 1993 book “Conduct Unbecoming,” about gay men and women in the military.

In later years, Mr. Baker often lectured about gay rights and had exhibitions of photographs and silk-screen prints of his rainbow flag. He sometimes dressed in drag under the persona of “Busty Ross.”

At a White House ceremony in 2016, Mr. Baker presented President Barack Obama with a framed copy of his original eight-color flag.

“The rainbow flag is a symbol of freedom and liberation that we made for ourselves,” Mr. Baker said in 2003. “We all own this flag.”