ROCKPORT, Me. — After several months of open deliberations about her future, Senator Susan Collins of Maine announced Friday that she would not run for governor and would remain in the Senate.

“I want to continue to play a key role in advancing policies that strengthen our economy, help our hard-working families, improve our health care system, and bring peace and stability to a violent and troubled world,” she said. “And I have concluded that the best way that I can contribute to these priorities is to remain a member of the United States Senate.”

Ms. Collins, a Republican who was first elected to the Senate in 1996, has become a thorn in the side of President Trump, for whom she did not vote. Most famously, she played a crucial role this summer in dooming his goal of repealing the Affordable Care Act.

Since April, Ms. Collins, 64, has toyed publicly with the idea of running for governor, which was the first office she ran for, in 1994. Though she lost that race, she said she was still drawn to the ability of a governor to have a direct and immediate effect on people’s lives by creating jobs and spurring economic development. She also said she felt an affinity for Augusta, the capital, where a long line of ancestors served in the State Legislature, starting with her great-great grandfather and including her father.

Had she run and won the race for governor in 2018, she would have become the first woman in Maine to hold the office.

Although she has been one of Maine’s most popular politicians for some time, there was no guarantee that she would win her party’s nomination in the June primary. Gov. Paul R. LePage, a fellow Republican who is barred by term limits from seeking a third term, has been stirring the political pot against her. Ms. Collins, a moderate who has glided to victory in her recent elections, this time faced the likely prospect of bruising and expensive attacks from the right.

Now in her fourth term in Washington, she ranks 15th among the 100 senators in seniority and appears to be at the height of her power. As one of the few moderates in a closely divided Senate, she is often a swing vote, and, as she demonstrated during the health care debate, she can often influence the outcome of important legislation. Since Mr. Trump became president, she has voted less often with her party than any other Republican senator.

By staying in the Senate, Ms. Collins “can continue to have a pretty interesting role as one of the few people who isn’t in lock step with one party,” said Stuart Rothenberg, a veteran political analyst for Inside Elections With Nathan L. Gonzales, a nonpartisan newsletter that analyzes campaigns.

“This will be bad news for Donald Trump,” he said, but good news for those on Capitol Hill “who are looking for dispassionate, pragmatic leadership and for members willing to cross party lines on important votes.”

Ms. Collins made her announcement at a breakfast meeting here of the Penobscot Bay Regional Chamber of Commerce. She kept the audience of about 225 people in suspense for more than half an hour as she discussed the pros and cons of the Affordable Care Act.

Finally, she turned to what she called “the elephant in the room.” She said a Senate colleague, whom she did not identify, had written her a note urging her to stay in the Senate. Ms. Collins read the note out loud: “The institution would suffer in your absence. While the temptation might be to walk away and leave the problems to others, there are very few who have the ability to bring about positive change. You are such a person.”

The audience applauded but still seemed uncertain of her decision, as she continued. “As I thought about this senator’s words, I realized how much remains to be done in a divided and troubled Washington if we are to serve the people of our states,” she said. “I have demonstrated the ability to work across the aisle, to build coalitions, and to listen to the people of my state and my country.”

She said she was “a congenital optimist” and believed that Congress could be more productive.