WASHINGTON ―The Electoral College formally selected Donald Trump as U.S. president on Monday, even as several electors bucked their states by opting to cast their presidential ballots for someone other than Trump or Hillary Clinton.

Members of the Electoral College met in their respective state Capitols to vote for the presidential and vice presidential candidates for whom they had pledged to vote earlier this year. Many electors, however, are not legally bound to vote for a specified candidate. Some electors ― known as “faithless electors” ― have in the past voted against their political party or abstained from voting altogether.

Trump hit the necessary threshold of 270 electoral votes after Texas’ representatives cast their ballots. At the end of the day, Trump had 304 electoral votes to Clinton’s 227, and seven votes were cast for others. Congress will meet in a joint session on Jan. 6 to officially count the Electoral College votes.

Maine Democratic elector David Bright announced in advance that he would cast his ballot for Sen. Bernie Sanders (I-Vt.), who lost to Clinton in the Democratic presidential primary.

“I cast my vote for Bernie Sanders not out of spite, or malice, or anger, or as an act of civil disobedience,” Bright said in a statement. “I mean no disrespect to our nominee. I cast my vote to represent thousands of Democratic Maine voters ― many less than a third my age ― who came into Maine politics for the first time this year because of Bernie Sanders.”

Maine is one of 29 states plus the District of Columbia that require its electors to cast their ballots for the person the elector is tied to ― in this case Clinton. Bright could face a fine for his actions, but no elector has been penalized in the past.

When Bright cast the Sanders vote Monday, it was ruled out of order. He then voted for Clinton instead.

AUGUSTA, Maine (AP) - Democratic Maine elector's vote for U.S. Sen. Bernie Sanders ruled improper; he switches vote to Hillary Clinton https://t.co/Fm1gfZbPNp — Josh Lederman (@joshledermanAP) December 19, 2016

One of Minnesota’s 10 electors, who was slated to vote for Clinton, refused to vote Monday, and was reportedly dismissed and replaced with an alternate.

One of 10 Minnesota electors has decided not cast a vote, Muhammad Abdurrahan. An alternate is now being sworn in. #ElectoralCollege pic.twitter.com/4eN1PIrZdO — Dylan Wohlenhaus (@DylanWohlenhaus) December 19, 2016

A Colorado elector was similarly replaced:

Hillary Clinton gets 9 Electoral College votes from Colorado after one elector is replaced when he refused to vote for Clinton. — Nick Riccardi (@NickRiccardi) December 19, 2016

In Washington state, four electors broke ranks, voting for former Secretary of State Colin Powell and for Faith Spotted Eagle, a Native American environmental activist.

Breaking 4 "faithless electors" break ranks in Washington state electoral college vote. 3 vote for Colin Powell, one for Faith Spotted Eagle — Ed Pilkington (@Edpilkington) December 19, 2016

Chris Suprun, a Republican elector from Texas, had said he would vote for Ohio Gov. John Kasich (R). In an op-ed earlier this month in The New York Times, Suprun said the president-elect “shows daily he is not qualified for office” and called on fellow electors to “do their job” and unify around an “honorable and qualified” alternative.

Suprun further explained his decision to vote for Kasich in a piece Monday in The Hill.

“Ronald Reagan did not win the Cold War so that Vladimir Putin could pick our next president less than 50 years later,” he said.

One Texas elector, presumably Suprun, voted for Kasich. Another elector voted for former Rep. Ron Paul (R-Texas).

Despite these defections, Trump’s formal election was never truly in doubt. He will be one of just five presidents to win the White House while losing the popular vote (since it was tracked starting in 1824). Trump trails Clinton by more than 2.5 million votes, the biggest margin in raw numbers by which a president has lost the popular vote.

To change the election results, 38 Trump electors would have had to defy their party and cast a ballot for another candidate. That was extremely unlikely. Nevertheless, activists sought to sway Republican electors to vote against the president-elect, citing the Electoral College as a necessary component of the federal government’s system of checks and balances.

Harvard Law School professor Larry Lessig, one of those activists, offered free legal aid to any electors breaking with their state in hopes of derailing Trump’s path to the White House.

“The motivation was the recognition that there were going to be a lot of electors who were considering what we believe is their constitutional right, to vote their conscience,” Lessig said.

Prior to Monday’s vote, Lessig estimated as many as 20 electors could flip ― a claim not supported by an Associated Press survey of electors nor the GOP’s own whip count.

This story was updated through the day with additional details about electors and their votes.