Maryland's legislature and governor enacted a law tonight that bans smoking in virtually all indoor workplaces except bars and restaurants, which Gov. Parris N. Glendening agreed to exempt in the interest of tourism and business.

The ban will force thousands of workers to snuff out cigarettes in corridors, factories, prisons and offices, making Maryland one of the toughest anti-smoking states in the nation. But smoking still is allowed, under certain circumstances, in any bar or restaurant.

The exceptions were forged hastily this morning in a race to head off a court-authorized prohibition on workplace smoking, including in bars. In agreeing to compromise with General Assembly leaders, Glendening backed away from his previous vow to veto any exemptions except for "very small restaurants and taverns."

"Tomorrow, when Marylanders wake up, our state will be practically smoke-free," Glendening said as he signed the measure into law.

The compromise was justified, he said earlier, to give "95 to 96 percent of all workers in Maryland" a smoke-free workplace. "There's always an opportunity to come back later for the last 4 or 5 percent."

The governor began retreating from a more wide-ranging smoking prohibition when lawmakers showed they probably would override a veto and when restaurant owners lobbied heavily to give virtually all dining establishments some means of providing smoking areas.

Glendening and lawmakers agreed today to allow smoking in up to 40 percent of any restaurant that wants it. Restaurants that do not serve alcohol or have bars would have to provide a separately enclosed dining room for smokers. Restaurants with bars could allow smoking at and near the bar, without building walls to separate smokers from nonsmokers.

By and large, restaurateurs with alcohol licenses greeted word of the compromise in Annapolis with joy.

Gravel-voiced Henry Vechery, owner of the Bethesda Crab House, was not thrilled about having the state tell him how to run his place. He worried that tough smoking rules would drive some customers over the Maryland boundary into the District of Columbia, where rules are looser. But today's compromise left him happy.

"I think that will satisfy everybody," he said. "I have no problems with it. The restaurants pay big rent today, and they need all the customers they can get."

Some businesses did not wait to see how things would shake out in the State House. Told early in the day that strict new rules were probably coming, managers at a Shoney's Restaurant in Gaithersburg banned smoking outright. Under the rules that finally passed, they probably would have to spend big money to build a separate room for smokers, so the ban might stay.

"We already had a couple of customers turn around and make a U-turn when they found out they couldn't smoke," general manager Frank Dauphin said. "But I believe once they get used to it, we should get pretty much the same clientele as before."

Anti-smoking groups said they were disappointed that Glendening's original position did not prevail, but they praised Maryland's law nonetheless.

"It's a mixed bag," said Eric Gally, of the American Cancer Society. "Restaurant and bar workers are those most at risk" from second-hand smoke.

Still, the law provides substantial protections to most Maryland workers, he said.

The Maryland law will allow local governments to enact tougher anti-smoking restrictions. Talbot County already has banned smoking in most workplaces, including restaurants.

Maryland's anti-smoking battle focused on restaurants and bars largely because smoking already is prohibited in many offices, shops and factories. Moreover, the tourism industry began lobbying the issue heavily, flooding legislators with letters and telephone calls warning that restaurants and convention sites would suffer if patrons could not smoke while eating and drinking.

Glendening found himself in a bind, because he had campaigned to reduce Maryland's cancer rate and also to make the state more business-friendly.

Glendening said today that he was worried legislators might carve even larger exemptions from the smoking ban if he did not reach an accord with them. "Sometimes you make some accommodations to make sure you keep most of what you are fighting for," he said.

The compromise's ink was barely dry when the Maryland Senate approved it 42 to 5 and whisked it across the hall to the House, where it passed 130 to 5. Glendening signed it a short time later.

The new law supersedes court-approved regulations that briefly took effect this afternoon. The regulations -- initiated by former governor William Donald Schaefer and approved by the state Court of Appeals -- would have banned smoking in virtually every workplace, including restaurants and bars.

Maryland's new law is designed to protect the health of employees, not restaurant patrons or other consumers. The state's labor department said it will accept complaints only from employees, who will be asked to write their grievance on a form. State officials then will send employers "a compliance package," advising on ways to meet the law's requirements.

Those who refuse to comply or respond will be given an initial warning, said Ileana O'Brien, deputy commissioner of labor and industry. Repeated violations could result in fines of up to $7,000, she said.

At the bar inside O'Donnell's restaurant in Bethesda, Leslie Lehr celebrated her birthday with a cigarette as she sat across a table from her mother, Lee Best. They were on their way to shop for a dress. The idea of a strong smoking ban offended Lehr.

"I think it's ridiculous," Lehr said. "I wouldn't light up a cigarette at my desk. But if I'm out in a bar or a restaurant and I want to light up a cigarette in the smoking section, I should be able to do that."

At George Starke's Head Hog BBQ in Bethesda, nobody was pleased about new restrictions on smoking. One end of the small restaurant, nearest the bar, already was set aside for smokers.

Day manager Danny Densmore is prone to light up on the job. The rib joint's president, who calls himself Smokin' Joe McKay, acknowledges his wife, who is pregnant, is on him to quit. But Densmore and McKay are ready to defend their rights as smokers. Whatever the state does, Densmore said, people are going to find a way to mix smoking, socializing and alcohol.

"Remember the old speakeasies, where you could knock three times and go inside and smoke and drink?" Densmore said. "We'll have to bring those back again." Staff writer Jon Jeter contributed to this report. GLENDENING AND THE SMOKING BAN Positions of Gov. Parris N. Glendening regarding smoking in Maryland restaurants and bars: * MARCH 2: Smoking will be allowed only in "very small taverns and restaurants. ... I will veto any effort to repeal this." * MARCH 10: Smoking will be allowed in bars and restaurants that serve alcohol and seat as many as 50 people. Larger restaurants can allow smoking in separately ventilated rooms. * March 17: Smoking will be allowed in all bars, regardless of size. * Friday: Smoking will be allowed at bars inside restaurants. Also, the separate dining rooms for smokers do not have to be separately ventilated. * Monday: All restaurants, including those that do not serve alcohol, may allow smoking in up to 40 percent of their space if they build a separate dining room. SOURCE: News reports CAPTION: Young Chi puffs away at the Rockville Billiard Club, where the clientele is made up mostly of smokers, for one last time. Maryland's new law allows smoking only in bars and restaurants under certain circumstances. CAPTION: Leslie Lehr, celebrating her birthday with a cigarette at the bar at O'Donnell's, a restaurant in Bethesda, says the smoking ban is "ridiculous." CAPTION: Day manager Danny Densmore has a smoke at George Starke's Head Hog BBQ in Bethesda. "Remember the old speakeasies, where you could . . . go inside and smoke and drink? We'll have to bring those back again," he says. (Photo ran in an earlier edition)