Gov. Bob Mc­Don­nell (R) scored a major unexpected victory late Wednesday when both the Democratic-controlled Senate and Republican-led House of Delegates voted to allow him to appoint a seat on the Metro Board of Directors, which he had been seeking since the start of his term.

He had been working for months to get a seat but had been thwarted several times by local officials in Northern Virginia, primarily Democrats, who opposed the effort.

The Senate voted 21-19, with three Democrats — Northern Virginia Sens. Chap Petersen, Chuck Colgan and Toddy Puller — voting with all Republicans. The House voted 62-34.

The amendment to the state’s two-year, $78 billion budget will force the Northern Virginia Transportation Commission, which is comprised of 19 local and state elected officials plus the state’s public transportation director, to give the state one of its seats.

Jay Fisette, NVTC’s chairman, said he was “shocked” the governor pursued the Metro seat through the state budget, noting that the WMATA board and the NVTC were already negotiating with him over the issue.

“By doing it in this way, he’s circumvented the process and done an end run around the ongoing conversations,” Fisette said.

The Metro board’s 14 members include two representatives from Fairfax County, one from Arlington County and the Alexandria mayor.

“The Governor appreciates the bipartisan support for this common sense proposal,’’ Mc­Don­nell spokesman Tucker Martin said. “Virginia deserves the same representation enjoyed by Maryland and the District of Columbia, and this vote ensures that will be the case. This is a positive step forward for improving transportation in the Washington D.C. metro area.”

Both Maryland Gov. Martin O’Malley (D) and D.C. Mayor Vincent Gray (D) have backed his effort.

In November, a task force of the Greater Washington Board of Trade and Metropolitan Washington Council of Governments recommended that Virginia, Maryland and the District change the Metro agreement to increase the number of members from each jurisdiction from two to three, with one member appointed by the chief executive of each jurisdiction.