Democrat Elizabeth Warren won re-election to the U.S. Senate, beating back a challenge from Republican state Rep. Geoff Diehl, and also independent candidate Shiva Ayyadurai.

The race was called for Warren as soon as polls closed at 8 p.m. With 88 percent of precincts in, Warren captured 61 percent of the vote, while Diehl took 36 percent. Ayyadurai grabbed 3.4 percent.

Several hours later, she thanked supporters in Boston for taking a chance six years ago on someone who had never run for office before.

“You took that chance,” Warren said. "You sent me into the fight, and tonight, you told me to stay in the fight."

Elizabeth Warren speaking to supporters after she handily won a second term to the U. S. Senate. (Jesse Costa/WBUR)

Warren pledged to resume the fight against what she called a "rigged system" and a "corrupt president" who is neglecting working Americans. And she saluted the record number of women candidates this year, which helped make history in Massachusetts.

Come January, the state will have four women in Congress for the first time ever: Warren in the Senate and three others in the House: Katherine Clark in the 5th district, Ayanna Pressley in the 7th district and Lori Trahan in the 3rd district. Warren said this historical moment is the result of a movement that began the day after Donald Trump's inauguration.

"They refused to let anyone shut them up or stand in their way," Warren told her cheering supporters Tuesday night. "That is how real change begins."

Warren's victory was never in doubt in this deep-blue state, in a race that reflected the nation’s stark divisions over Trump. The contest was a clash over Diehl's support for Trump and Warren's potential interest in replacing him.

Republican Senate nominee Geoff Diehl at WBUR (Robin Lubbock/WBUR)

During his campaign, Diehl frequently attacked Warren for her apparent desire to run for president, which he said would make her a part-time presence in Massachusetts.

But Tuesday night, Diehl conceded defeat in his hometown of Whitman.

"While the outcome is not what we wanted, we've laid the foundation for taking Massachusetts back for working people," Diehl said. "I am a firm believer that when God shuts a door, he opens a window somewhere. So, together, we're going to find that window."

Diehl, who co-chaired Trump's presidential campaign in Massachusetts, stayed clear of the president's divisive rhetoric, but he embraced most of Trump's polices, including a tough line on immigration and sounding the alarm about the so-called migrant caravan heading toward the U.S.-Mexico border.

Concern about immigration was among the reasons John Strang, a Republican from Fitchburg, voted for Diehl.

"We should maintain our borders," Strang said. "We are a sovereign state. We have opportunities for people to come here legally, and anyone in this so-called caravan can take advantage of those opportunities. But the notion that you're going to bulldoze your way through the border based on liberal and media sympathy — that doesn't wash."

But promoting Trump's policies was a hard sell in Massachusetts.

"The people who like it in Massachusetts love it," said Erin O'Brien, a political scientist at the University of Massachusetts Boston. "But there just aren't enough of them for Geoff Diehl to carry the day."

While Diehl tried to make the case that sending a Republican to Washington would give Massachusetts "a seat at the table," Warren labeled him a Trump ally who would work against the interests of most Bay State residents. She campaigned on issues important to many Massachusetts voters, including abortion rights, LGBTQ rights, gun control and support of the Affordable Care Act.

But her most effective campaign weapon against her opponent was to consistently link him to the president, who remains deeply unpopular in Massachusetts.

"Mr. Diehl has said that if he's elected he will have Donald Trump's back 100 percent of the time," Warren said in her second debate with Diehl.

"She's a good fighter," said Bob Welch of Somerville. "And we need her [in Washington]."

"We need her to fight against Trump," added Welch's wife, Peggy.

Warren also railed against the Republican tax cut as a boon for billionaires and large corporations at the expense of working Americans. And she ran on an anti-corruption message, calling the Trump White House "the most corrupt administration in living history."

The most recent WBUR poll, released days before the election, found that "fighting government corruption" was the most important issue in the Senate race, beating out the cost of health care, addressing climate change or standing up to Trump.

It was a message that appealed to Democrats as well as many unenrolled voters, including Diana Bernstein from Holden.

"I like how she's fighting for the little guy," Bernstein said, "and for women, minorities, everyone."

Now that Warren has won re-election, the big question is: Will she run for president in 2020? Warren has said that she will give it "a hard look," and has already laid some of the groundwork for a presidential run, including dispatching staffers to some key early primary states.

Mary Anne Marsh, a Boston-based Democratic political consultant, said the fact that Warren has emerged as one of Trump's toughest critics puts her in a strong position among early presidential hopefuls.

"If you’re a Democrat, you are measured by the strength of your opposition to Donald Trump," Marsh said. "Nobody has bedeviled [him] like Elizabeth Warren."

If she decides to run, her speech Tuesday night in Boston laid out her case. It was a hard-charging populist message about a broken government that serves the powerful at the expense of ordinary Americans.

"Our government is still captured by the wealthy and the well-connected," Warren said. "And the economy is still rigged against working people, women and communities of color."

Richard Shea, a Democrat from Worcester who voted for Warren, says he hopes she decides to run for president.

"She has a good background," Shea said. "She's very smart, and I think she's going to be the first female president of the United States."

But some will question whether a former Harvard professor from one of the country's most liberal states is the right choice to take on Trump in 2020. The most recent WBUR poll of likely Massachusetts voters found that a large majority — 63 percent — said Warren should not run for president.

But that didn't stop many of them from giving her a second term in the Senate.