Maryland state senators on Monday signed off on legislation that would make undocumented immigrants eligible for in-state tuition benefits at the state’s public colleges.

After a lengthy and emotional debate, the Senate voted 27 to 20 to approve the measure, shifting one of the legislative session’s most high-profile and controversial immigration bills to the House of Delegates.

Sen. Victor R. Ramirez (D-Prince George’s), the lead sponsor, spoke to dozens of students seated in the gallery who would benefit from the measure, and told his story of arriving legally in the United States from El Salvador at age 5.

“This is about education; it’s not about immigration,” he said. “What do we do with the talent and the intellect of the children of undocumented immigrants who are already living here? These children didn’t make the decision to come to Maryland. Their parents did.”

Republican opponents and some Democrats said the state should not be subsidizing the cost of higher education for illegal immigrants, and that their objections were a matter of fairness.

The bill “sends a terrible message,” Sen. Allan H. Kittleman (R-Howard) said. “We’re telling our students, ‘It’s okay to break the law, and you’ll get a benefit.’ ”

The measure passed by the Senate is a scaled-back version of what proponents initially envisioned. It calls for Maryland high school graduates, regardless of immigration status, to initially qualify for tuition breaks only at the state’s community colleges. Those who receive an associate’s degree could transfer to one of Maryland’s four-year institutions and pay the in-state rate.

The compromise is an acknowledgment of heightened national debate over illegal immigration in states such as Arizona, and increased competition for slots at some of Maryland’s universities.

Outside the Senate chamber Monday night, students celebrated the vote, waving American flags and wearing faux graduation caps.

“It’s going to be so much easier for me,” said Bryan, a Prince George’s County high school student from Guatemala who plans to apply to college in two years. “I never thought we’d do it. I’m just so thankful.”

Supporters said the out-of-state tuition rate — an average of $10,000 more each year — makes higher education cost-prohibitive for most undocumented immigrants. Students would have to provide proof that their parents are Maryland taxpayers, and commit to seeking permanent residency.