William Donald Schaefer, who dominated Maryland politics as governor, state comptroller and Baltimore mayor with a trademark style that was impatient, autocratic and sometimes offensive, died Monday of undisclosed causes at a retirement center in Catonsville, Md. He was 89.

As Baltimore mayor from 1971 to 1987, Mr. Schaefer gained national exposure as he revived the fading industrial city with massive cleanup and construction efforts. He transformed a riot-torn metropolis into the tourist-centered “Charm City,” which included the Harborplace urban market and aquarium, as well as Oriole Park at Camden Yards.

Mr. Schaefer was incapable of passing up any stunt to draw media attention to his city or himself. He famously turned a construction delay of the Baltimore aquarium in 1981 into a public relations win by plunging into the seal tank while wearing a Victorian-era swimsuit and holding a rubber duck.

Starting in 1986, he was twice elected governor and continued what he called his “do it now” approach to expensive infrastructure projects. He said he embraced his image as an eager-to-spend Democrat, even as a national recession in the early 1990s — which he inaccurately predicted would fade quickly — led to major tax increases and budget cuts.

As governor, Mr. Schaefer lured major corporations to the economically depressed areas of Western Maryland, pushed successfully for environmental legislation to help clean the Chesapeake Bay, widened roads to the Atlantic shoreline and used much political capital in 1988 to back the first statewide referendum on gun control ever approved by a state legislature.

To push through the referendum, Mr. Schaefer lobbied intensely to defeat a heavily funded opponent, the National Rifle Association. Mr. Schaefer had the political support of law enforcement officers, newspaper editorials and religious leaders.

Mr. Schaefer later tried repeatedly and unsuccessfully to ban the sale and manufacture of some assault weapons. He greatly hurt his cause at a news conference by pointing an unloaded semiautomatic gun at an Associated Press reporter.

“Some of you have never had it in your face,” Mr. Schaefer said, explaining an action most gun enthusiasts consider highly irresponsible.

Waving the gun was not out of character. As mayor, he once yelled at the secretary of the U.S. Department of Housing and Urban Development when he thought Baltimore was shortchanged on grant money. He irritated the official but got the money.

He addressed a newspaper editor with “Dear Edit-turd.” He answered one angry taxpayer’s letter with, “I’m glad you have recovered from your lobotomy.” He likened the conservative, rural Eastern Shore — which had not voted for him as governor — to an outhouse. He taunted his gubernatorial successor, Parris N. Glendening (D), by clucking and flapping his arms and calling him a chicken.

In Baltimore and Annapolis, he never tolerated dissent and rarely consulted legislators. He likened compromise to indecision. He was perpetually unsatisfied, once saying he thought himself a legislative failure “unless we get 105 percent of what we have proposed.”

Legislators spoke of Mr. Schaefer’s tendency toward moodiness and holding grudges.

His lieutenant governor, Melvin A. Steinberg, a former state Senate president, once urged compromise on a tax restructuring plan and refused to lobby for his boss on the measure as it stood. Mr. Schaefer took Steinberg off several committees and removed two of his five aides. Eventually, Mr. Schaefer and Steinberg stopped talking.

Then-state Sen. Paula C. Hollinger (D-Baltimore County) once said of Mr. Schaefer, “He’s like the nursery rhyme about the little girl with the curl in the middle of her forehead: When he was good, he was very, very good, and when he was bad, he was horrid.”

Mr. Schaefer said a rough-edged personality was necessary to hold power. One of his civic heroes, Chicago Mayor Richard J. Daley, advised him to do things first and seek approval after the fact.

“I knew I had to be a mean sonofabitch,” Mr. Schaefer once said. “I couldn’t afford to get close to anyone. I wouldn’t have gotten anybody to do anything.”

George H. Callcott, a retired University of Maryland professor who specialized in Maryland history, said Mr. Schaefer was an “able administrator. . . efficient and clean,” but not a bold or eloquent leader.

He said Mr. Schaefer’s overall political career lacked a “great vision, ideology or program, except for the consistent program of developing Baltimore City, which he did as mayor and governor.”

Even to that end, Callcott said, Mr. Schaefer managed to slow down, but not halt, Baltimore’s loss in population and tax money, and crime remained a concern.

William Donald Schaefer was born in Baltimore on Nov. 2, 1921. His father, a title lawyer, moved the family to the western end of the city, where his only child was given the largest bedroom in the house. Mr. Schaefer spent much of his adult life in the same rowhouse caring for his mother, Tululu.

She was said to be the only woman in his life until 1959, when he met Hilda Mae Snoops, a divorced mother of three. Snoops, who became his de facto first lady in the governor’s mansion, died in 1999, and Mr. Schaefer leaves no immediate survivors.

Mr. Schaefer served in the Army during World War II and graduated from the University of Baltimore’s law school. He entered politics after a brief period as a real estate lawyer.

After a few unsuccessful races, he met Irvin Kovens, a discount furniture dealer and Democratic power broker. In 1955, Kovens was looking for a gentile candidate — Mr. Schaefer was Episcopalian — to round out a slate of Jewish politicians in a city district for a council seat, according to Mr. Schaefer’s biographer, C. Fraser Smith.

Mr. Schaefer showed no aptitude for the ethnic clubhouse politics, but he had an unquestioned knowledge of bylaws and budget preparation. He made his ward’s voters happy by seeing to their immediate needs, such as potholes and trash collection.

He was smitten his whole political career with beautification — erecting fountains, planting flowers and urging people to repair dilapidated homes. Mr. Schaefer habitually attacked neighborhood problems by issuing to his aides thousands of “action memos” to clean up litter, abandoned cars and stray dogs.

“One thing I learned, make the city fun,” he told The Washington Post in 1995. When a water main broke, he instructed city workers to erect a sign saying, “New Fountain in Your Neighborhood.”

Mr. Schaefer became council president in 1967 and succeeded Mayor Thomas J. D’Alesandro III (D) in 1971.

Baltimore’s revival had begun in the early 1960s with the Charles Center business complex. Under Mr. Schaefer, the city implemented plans to use the waterfront area to keep people downtown after working hours. The aquarium became a centerpiece. The mayor also helped bring in architect I.M. Pei to design the city’s World Trade Center and courted businesses such as Hyatt to build a large hotel at the harbor.

An issue that Mr. Schaefer treaded carefully was race, especially as his tenure saw the city’s population become majority black. He reportedly wanted to address the city’s poorly performing school system but worried that any criticism of the predominantly black Board of Education would reflect badly on him.

Biographer Smith wrote: “He was caught between conflicting expectations: He was expected to stay out of — and to reform — a system that increasingly failed to prepare its students for productive lives. . . . Baltimore’s school system represented everything Schaefer disliked: It was the classic institutional aircraft carrier that does not easily turn at the captain’s command.”

Many of Baltimore’s black leaders expressed concern that their neighborhoods were being left behind during the city’s transformation.

Former delegate Timothy F. Maloney (D-Prince George’s), a Schaefer admirer, said that the mayor tried to be vigilant about all neighborhoods but that on big renewal efforts, he focused on areas of the city that tourists were likely to visit.

“He was interested in doing things that were practical,” Maloney said. “You’re not going to build an aquarium [in poor neighborhoods far from the city center] and expect people to come out there.”

By the mid-1980s, Mr. Schaefer was the most visible politician in the state. Esquire magazine named him “best mayor in America” in 1984. He was lobbied by state power brokers to run for governor.

In a landslide win in 1986, he became Maryland’s 58th governor, succeeding Harry R. Hughes (D). He stormed Annapolis with his requests, expecting and largely getting them approved.

He once greenlighted a $50 million oncology building for the University of Maryland Medical System and halved the time of completion through his knowledge of the state’s bureaucracy.

He oversaw the revamping of the higher education system with College Park as the capstone of the university system. With all the state schools operating under a single board, they could make requests of the General Assembly from a more united and powerful position.

He won General Assembly approval to build Oriole Park and a stadium for a prospective National Football League team to replace the Colts, which had abandoned Baltimore in 1984. The Cleveland Browns were lured to Baltimore in 1996, after Mr. Schaefer left the governorship, and were renamed the Ravens.

Mr. Schaefer also pursued wetlands protection and transportation and educational building projects with great fervor and with admitted disregard for the coming national recession. “I never planned beyond a year,” he once told The Post.

When Maryland was left with large budget deficits, Mr. Schaefer implemented highly unpopular tax increases. He also made budget cuts to welfare benefits and education measures he had increased during his first term.

Callcott, the U-Md. professor, said Mr. Schaefer accepted the blame for the cutbacks and created a “leaner and more efficient government in the process.” But in the short term, businesses began leaving the state, and the austerity measures spurred a backlash in the General Assembly against his demanding manner.

After leaving the governor’s mansion in January 1995, Mr. Schaefer held a part-time teaching job at U-Md. but was said to be restless. Longtime comptroller Louis L. Goldstein died in office in 1998, and Mr. Schaefer pounced on the chance to run for that job, a position of great influence over the state’s business contracts.

Mr. Schaefer used his new position as a personal sounding board, often on subjects of no relevance to his job.

In 2004, Mr. Schaefer was severely criticized for saying that people with AIDS “bring it on themselves” and for advocating that state health officials create a public registry of people with AIDS. He withdrew that request.

He also made insulting remarks about Spanish-speaking restaurant workers.

He fought attempts to silence him by passing out a bumper sticker reading, “Mr. Schaefer: He says what you think.”

At age 84, while at a State House gathering, he asked a young gubernatorial aide to walk past him again so he could watch her posterior. After lashing out at the media for publicizing the story, he grudgingly sent a written apology to the woman: “Sorry you were put thru an ordeal.”

Much of this behavior, compounded by unkind statements he made about the physique and dress habits of another contender, Anne Arundel County Executive Janet S. Owens, accounted for his loss in the 2006 Democratic primary. Del. Peter Franchot (D-Montgomery) swept Mr. Schaefer from office.

For a man who admitted his work was his life, Mr. Schaefer briefly pondered running for mayor of Ocean City, where he often vacationed and liked to sit on the beach alone.

He also enjoyed raising African violets, listening to singer Engelbert Humperdinck and watching the wrestler Hulk Hogan.