Sen. Stanley Rosenberg was elected by his colleagues Wednesday to serve in the powerful position of president of the Massachusetts Senate, and immediately promised the Democratic-controlled body would work cooperatively with the state's incoming Republican governor.

Rosenberg, a 65-year-old Democrat from Amherst, succeeds Therese Murray, a Plymouth Democrat who retired after nearly eight years as Senate president. He is the first openly gay lawmaker chosen to lead either of the state's legislative chambers, and the first legislative leader from western Massachusetts since the early 1970s.

All 34 Democrats backed Rosenberg for the post, and the six Republicans in the chamber later moved to make the selection unanimous.

Rosenberg, in his acceptance speech after being elected Senate president, promised to work cooperatively with Republican Charlie Baker, who will be sworn in as the state's next governor on Thursday.

"We will have our differences, but it's neither our job nor our inclination to obstruct him for obstruction's sake," Rosenberg said.

Rosenberg specifically called for passage of an expanded earned income tax credit, something Baker had strongly supported during his gubernatorial campaign as a means of helping low-income taxpayers.

A 24-year veteran of the Senate who most recently served as majority leader, Rosenberg was elected despite a recent controversy surrounding his domestic partner, Bryon Hefner. The Boston Globe reported last month that Hefner had raised eyebrows by mocking Murray on Twitter and boasting that he would exert influence on legislative affairs.

Rosenberg responded with a letter to colleagues in which he promised a "firewall" between his private and professional life.

In his speech, Rosenberg thanked Hefner, 27, for standing by him in good times and bad.

"You are awesome," he said to applause from senators.

Rosenberg is generally viewed as more liberal on many issues than his predecessor, Murray, and DeLeo. But he told reporters after his election that he intends to pursue a "pragmatic agenda," that seeks to boost the economy and create jobs.

"I don't think that's a liberal idea, I don't think that's a conservative idea," Rosenberg said. "I think that's a basic American idea."