David Stern, who served as commissioner of the National Basketball Association for three decades, transforming a struggling league plagued with image problems into a billion-dollar business whose games are viewed by fans in more than 200 countries, died Jan. 1 in New York.

He had a brain hemorrhage while dining in New York on Dec. 12 and was taken to a hospital but did not recover. The NBA announced his death Wednesday afternoon. He was 77.

In a league of tall, sleek athletes capable of performing seemingly superhuman feats on the basketball court, the unathletic, 5-foot-9 Mr. Stern was unquestionably the most dominant figure in the NBA. A lawyer and league official before he was named commissioner in 1984, he stabilized a league that was tottering with its fan base shrinking and many of its teams losing money.

At the time, the NBA had 23 franchises, but the league was fading in popularity and public prominence. By the early 1980s, the NBA Finals were not even carried on live TV: They were shown late at night on tape delay. One season, no companies bothered making NBA trading cards.

Mr. Stern quickly consolidated power in the league’s headquarters, revamping business operations from the ground up. He instituted a draft lottery, in which the league’s worst teams were given the first chances to draft the best eligible players. (Previously, the two worst teams flipped a coin to see which would receive the top draft choice.)

The subsequent player draft became a huge media event that drew intense interest from fans and was presented live on television, with Mr. Stern announcing the draft picks and shaking hands with players who towered over him.

He led the NBA’s expansion to 30 teams, pushed out incompetent owners and encouraged struggling franchises to move to other cities. He negotiated broadcast contracts worth hundreds of millions of dollars; was instrumental in launching the WNBA, a women’s professional league under the NBA’s auspices; and brought a fresh approach to marketing that took advantage of the sport’s youth, diversity and international appeal.

When he took over the NBA’s top job, the league had 24 employees. When he retired in 2014, it had 1,200 employees, with offices all over the world, including three in China.

“Nobody, including me, envisioned that this young, bright attorney would have such marketing genius,” Abe Pollin, then owner of the Washington NBA franchise, told Sports Illustrated in 1991.

In perhaps his most significant innovation, Mr. Stern encouraged the NBA to present its players almost as if they were movie stars or superheroes. Michael Jordan, Magic Johnson, Larry Bird and LeBron James became household names around the world, largely as a result of marketing strategies devised by Mr. Stern and other league officials.

By the 1990s, basketball was challenging soccer as the world’s most popular sport, and the NBA began to draw players from Europe, South America, Africa and Asia. Games were broadcast in more than 40 languages, throughout at least 200 countries — more than are in the United Nations.

“David has taken us to another level,” Johnson, the onetime superstar of the Los Angeles Lakers, told USA Today in 1990. “He’s a great commissioner but also a mastermind at marketing, and that’s where he’s passed everyone else in sports. . . . We’re the hottest league in the world, not just the United States, but the world, and he’s the reason why.”

Players and team owners prospered through revenue-sharing and a salary cap. Annual player salaries rose from an average of $275,000 when Mr. Stern became commissioner in 1984 to more than $5 million when he stepped down 30 years later. In the early 1980s, some NBA franchises sold for less than $10 million. Today, the average value of a franchise is $1.9 billion, with the top clubs worth $4 billion or more.

Describing himself as “the chief executive officer of an entertainment company,” Mr. Stern brought a fresh emphasis to the NBA’s back-shop operations, bringing in millions from the sale of clothing, videos and other merchandise.

In the 1980s, Mr. Stern remade the NBA’s annual All-Star Game as a three-day extravaganza, with slam-dunk and three-point shooting contests that showed off the players’ extraordinary skills.

He worked with the International Olympic Committee to allow NBA players to compete in the Olympic Games, beginning in 1992, bringing new luster to both the Olympics and the sport of basketball.

Mr. Stern applied ideas from show business, often far removed from sports. One of the business models he emulated was Disney World.

“They have theme parks,” he told Sports Illustrated in 1991, “and we have theme parks. Only we call them arenas. They have characters: Mickey Mouse, Goofy. Our characters are named Magic and Michael. Disney sells apparel; we sell apparel. They make home videos; we make home videos.”

No aspect of his sport was too small to escape his attention.

“Game presentation is vital,” he told the New York Times in 1990. “The way fans are shown to [their] seats, the music, how breaks in action are used, the cheerleaders, how the arena is dressed, whether you play two minutes of a song and end on an upbeat.”

Mr. Stern was regarded as among the most effective sports commissioners in history, ranking alongside Kenesaw Mountain Landis, who cleaned up baseball after the “Black Sox” gambling scandal in the 1919 World Series, and Pete Rozelle, who built the National Football League into a nationwide phenomenon through television and the Super Bowl.

“He has turned the NBA into a leading global brand, not typically the way that people think of a sports league,” Adam Silver, Mr. Stern’s successor as NBA commissioner, said on “The Charlie Rose Show” in 2013. “I would say if you looked at a list of the top global brands in the world, brands like Coca-Cola, brands like Apple, I think the NBA deserves to be on that list.”

David Joel Stern was born Sept. 22, 1942, in New York. His parents ran a delicatessen in the Chelsea part of Manhattan, and as a child Mr. Stern walked 10 blocks from his home to Madison Square Garden to watch New York Knicks games.

He was 12 when his family moved to Teaneck, N.J., where he completed high school. He graduated in 1963 from Rutgers University and in 1966 from Columbia University’s law school. He then joined the New York law firm of Proskauer, Rose, Goetz & Mendelsohn, which had the NBA as a client.

His first major case involved a lawsuit filed by Connie Hawkins, who charged that the NBA unjustly kept him out of the league because of his involvement in a cheating scandal years earlier in college. The case was settled out of court, and Hawkins entered the NBA.

Mr. Stern also handled an antitrust case involving Hall of Fame player Oscar Robertson that ultimately led to free agency for NBA players. In 1976, Mr. Stern helped arrange for four teams from the rival American Basketball Association to be absorbed by the NBA.

He joined the NBA’s league office in 1978 as its first general counsel, and two years later he became executive vice president to Commissioner Lawrence F. O’Brien Jr.

In 1983, Mr. Stern hammered out a landmark agreement with the National Basketball Players Association, averting a strike by developing the first revenue-sharing plan in American sports. In exchange for a salary cap — originally set at $3.6 million per team — the players would receive 53 percent of the league’s total revenue. Both figures have been continually revised, with the arrangement leading to greater stability in the league, as small-market teams could compete more evenly with wealthier franchises.

“We were on the precipice,” Mr. Stern told New York Newsday in 1987, “and we managed to sit down with our players and make a deal that made us partners of a type, and you can’t overemphasize the importance of that.”

Mr. Stern’s management of the NBA yielded immediate dividends, with soaring revenue, record attendance, lucrative TV contracts and renewed interest in professional basketball. He was instrumental in implementing a drug-treatment program that was considered the gold standard in sports — but any player who refused to enter the program could be banned from the league for life, and at least nine were.

His skills were so widely respected that Major League Baseball and the NFL asked him to move to their sports as commissioner, but he turned them down. One of his former top lieutenants, Gary Bettman, has been the commissioner of the National Hockey League since 1993.

Mr. Stern was approachable enough that his employees called him “David,” but they also recognized he could be demanding.

“There would invariably be a point during the day when he would absolutely destroy you,” NBA executive Rick Welts told Sports Illustrated in 2006. “You’d feel as tall as an ant over something you mishandled. [Then] your phone would ring at 10 o’clock at night, and by the time you were finished talking to him, you were ready to charge into the office to do battle on behalf of the NBA.”

The league’s disciplinary standards could be harsh, and Mr. Stern fined Dallas Mavericks owner Mark Cuban more than $1 million for various infractions. He issued season-long suspensions to the Golden State Warriors’ Latrell Sprewell, after he choked his coach in 1997, and to the Indiana Pacers’ Ron Artest (now Metta World Peace), who went into the stands to fight spectators at a game in 2004. In 2010, the NBA suspended Washington Wizards players Gilbert Arenas and Javaris Crittenton for the remainder of the season for bringing guns into the team’s locker room.

The lowest point of his term as commissioner, Mr. Stern said, came in 2007, when an NBA referee, Tim Don­aghy, pleaded guilty to betting on games that he officiated. He was sentenced to 15 months in federal prison.

In a league whose players are overwhelmingly African American, Mr. Stern sought to encourage diversity and social responsibility. He helped establish organizations such as Basketball Without Borders and NBA Cares to promote the sport around the world and to support education, fitness and environmental causes.

At times during Mr. Stern’s tenure, the league and the players could not reach a contract agreement, resulting in lockouts and strikes that eliminated parts of several seasons.

“I had many moments with him during union meetings, during lockouts, where he could be just ruthless,” Steve Kerr, a onetime player and the current Golden State head coach, told the Los Angeles Times in 2014.

Kerr then added: “I think he’s going to go down as probably the greatest commissioner ever in sports, when you consider where the league was when he took over. . . . He seemed to be ahead of his time before the age of social media. It just felt like the NBA was always sort of two steps ahead of everybody, and I think David Stern has everything to do with that.”

Mr. Stern was inducted into the Naismith Memorial Basketball Hall of Fame in 2014.

Survivors include his wife of 56 years, the former Dianne Bock of Scarsdale, N.Y., and two sons, Andrew Stern and Eric Stern.

As the NBA’s longest-serving commissioner, Mr. Stern traveled the world on behalf of his league, meeting sports and business executives, government officials, former players and anyone else who could help broaden basketball’s global reach.

“Congratulations on a great job,” he told his staff after an exhausting day’s work. “And, as usual in the NBA, your reward for working hard is more hard work.”

A previous version of this story incorrectly stated that NBA teams draw numbers to determine the order in which they will draft players. The teams do not draw numbers; their names are drawn from envelopes. The story also implied that the lottery and the player draft occur at the same time. The player draft takes place after the lottery.