The Maryland Senate voted narrowly yesterday to legalize slot machines at four racetracks in a measure that would turn the state into a gambling hub on the East Coast and raise an estimated $700 million a year for public education.

Gov. Robert L. Ehrlich Jr. (R) has already endorsed the bill, but it faces strong opposition in the House of Delegates, where Speaker Michael E. Busch (D-Anne Arundel) has vowed to kill it unless he wins major concessions from the governor.

The gambling debate has bitterly divided the General Assembly since it convened in January, and yesterday's decision showed that a middle ground has yet to emerge. Despite heavy lobbying by Ehrlich, Senate President Thomas V. Mike Miller Jr. (D-Prince George's) and racetrack owners, the bill squeaked by on a 25 to 21 vote, with one abstention, as several senators switched sides at the last minute.

Sen. James E. DeGrange Sr. (D-Anne Arundel) voted in favor of slots despite having signed a pledge last year not to do so. As recently as Wednesday, he insisted that he would oppose the bill. But he changed his mind yesterday, saying slots were necessary to rescue the state from its $2 billion budget shortfall.

"This is probably the hardest decision in my political career," he said. "In making this decision, I know I'm going to upset some folks. But this is a way to avoid other taxes."

Another swing vote was Sen. Leonard H. Teitelbaum (D-Montgomery), who relented in his opposition after hearing from Miller and Ehrlich. Teitelbaum said he became a reluctant slots convert after the governor and Senate president persuaded him that deep budget cuts would be forthcoming if the gambling measure failed.

"They basically said they needed my vote, that this was a critical issue," he said. "I said to myself, hey, I got to do what's right. If we didn't pass the slots, the cuts would have been so dramatic that it would impact all of our social programs."

Except for a handful of small exceptions carved out for nonprofit groups, slot machines have been banned in Maryland since 1968. But pressure to bring them back has been building since the mid-1990s, when Delaware and West Virginia legalized them at racetracks and began attracting thousands of gamblers a day across Maryland's borders.

The Senate bill would permit 10,500 slots at three racetracks: Pimlico in Baltimore, Laurel Park in Anne Arundel County and Rosecroft Raceway, a harness track in Oxon Hill. A fourth track scheduled to open in 2006 in Allegany County would get 1,000 of the machines. That would be more slot machines than any East Coast state other than New Jersey, which has casino gambling in Atlantic City.

A public education trust fund would receive 46 percent of the gross revenues from slots, estimated at $1.5 billion annually. Local governments, the state lottery commission and horse-racing interests would each get a 5 percent cut.

The remaining 39 percent -- about $595 million a year -- would go to track owners. They would be required to invest $150 million at each track to build the slots parlors.

Their exclusive licenses to run slots would cost $5 million apiece and last for 15 years, with an option to renew.

Ehrlich praised the vote but acknowledged that slots face an uncertain fate in the House.

"We understand this bill has a long way to go," he said. "It's a very fluid process. But we do believe that today was a step in the right direction."

House leaders have passed a bill that would create a commission to examine the ramifications of gambling but have shown little inclination so far to approve slots this year. Some delegates have floated proposals that would tie slots to a 1-cent increase in the sales tax or an increase in income taxes for the wealthy, but Ehrlich insisted again yesterday that he would reject such compromises.

"No taxes, no taxes, no taxes," the governor said, citing his campaign promise not to raise sales or income taxes. "The election is relevant here. The election was about change. People saw a problem, and the problem was overspending during good times. And they elected us to fix it during a very bad time."

Busch also displayed little inclination to budge.

He said the narrow margin of approval in the Senate "shows there's still a lot of unanswered questions. I don't think it changes anything."

The pressure to cut a deal is expected to rise as time runs out on the legislative session. The General Assembly is scheduled to adjourn April 7.

Some pro-gambling lawmakers said bluntly that Ehrlich will have to change his mind and swallow a big tax increase if he wants slots to pass the House.

"We've learned with this governor that he has already changed his position," said Sen. Ulysses Currie (D-Prince George's). "If he wants the slots bill, he's going to have to support a large revenue measure."

The vote in the Senate split along unusual lines.

In past years, the Republican caucus almost unanimously opposed slots, but yesterday it voted in favor by a 10-to-3 margin, with one abstention, in a sign of support for the first GOP governor in more than three decades.

And while leaders of Maryland's Legislative Black Caucus have pushed hard for slots, only four African American senators voted in favor, with six against.

The Senate debated slots for 90 minutes in front of a gallery packed with lobbyists for racetracks and casino companies, who kept a close eye over the proceedings. Just outside the chamber, Ehrlich and several aides closeted themselves inside Miller's office and tried to pin down wobbly senators.

The debate, while spirited, was not rancorous. Miller persuaded two leading slots foes -- Sens. Brian E. Frosh (D-Montgomery) and Thomas M. Middleton (D-Charles) -- to mute their opposition. Frosh said nothing during the debate, and Middleton spoke only briefly.

Other critics slammed the bill as a giveaway to track owners, saying they would profit at the expense of schoolchildren and other needy causes. They predicted a rise in crime, corruption and other social ills.

"We've made a pact with the devil, and I'm not talking about Lucifer," said Sen. Paul G. Pinsky (D-Prince George's). "We're making a pact with a bunch of greedy men who stand to make a lot of money."

Advocates cast the bill as the lesser of two evils. They said that if lawmakers didn't approve gambling on a large scale, they would have to impose painful spending cuts that would result in shuttered nursing homes, children without health insurance and failing schools.

Sen. Nancy Jacobs (R-Harford) said she had firsthand knowledge of the harm gambling can cause but felt compelled to vote for slots anyway.

"I have a brother who is a compulsive gambler and destroyed his family because of it," Jacobs said. "I don't want to cast this vote. . . . But I don't see another way out. It might not be the right thing to do in my heart, but it's the right thing to do for my state."

Staff writer Lori Montgomery contributed to this report.