Standing in Gov. Charlie Baker's office Thursday afternoon, Stephanie Bellapianta, a college student and member of the group Teens Leading the Way, watched as civics education measures she'd been advocating for over the past seven years officially became state law.

"It felt great," Bellapianta said over the phone later in the day. "It felt like we were able to accomplish something huge."

Bellapianta was among the attendees at an unannounced invitation-only bill signing in Baker's office, where the governor approved legislation bolstering the state's civics education requirements, establishing a high school voter challenge, and requiring public schools to provide a student-led civics project for eighth graders and high schoolers.

The project component is intended to give young people hands-on practice in how their government works, similar to the experience youth advocates — one of whom is now a state representative — gained over the years they've spent promoting civics education.

"This has been very important for young people such as myself because it grants us the opportunity to be actively involved and engaged within the civics process, and we know that when we are given an opportunity to do so that young people will be able to rise to the occasion, to be great citizens," Bellapianta said.

Rep. Andy Vargas, a Haverhill Democrat who joined the House after winning a special election last year, visited the State House for the first time eight years ago as a high school student to lobby for a version of the bill. He gave his first speech as a lawmaker on civics education, and said in a statement Thursday that he hopes the bill results in more young people voting, volunteering and running for office themselves.

"We can have hopefully a lot more Rep. Vargases in the future," said Sen. Harriette Chandler, a Worcester Democrat who sponsored the bill (S 2631).

After the House and Senate passed differing civics education bills, a conference committee produced a compromise bill that legislators sent Baker in late July. He returned it in early August with an amendment specifying the voter registration challenge is nonpartisan and allowing students to opt out of a particular project and pursue an alternative one.

The Senate on Oct. 29 amended the bill, and both branches approved it again, sending it back to Baker.

Rep. Linda Dean Campbell, the bill's House sponsor, said it was "worth waiting for" and that the input from different groups improved the legislation.

"All of these organizations have been working on this for so long that there was so much momentum, we knew that this time we were going to get it done. We just wanted to make sure that everyone was comfortable with the fact that this was a completely nonpartisan piece of legislation," the Methuen Democrat said. "There's no agendas here, and we wanted to make sure that we took the time to ensure that this was going to happen and that we were all on the same sheet of music in that regard."

Thursday was the deadline for Baker to act on the bill. His public schedule for the day did not include any events related to the civics bill. And his aides did not respond to an inquiry about the bill about a half-hour before the signing, or when asked later why the media had not invited. The governor's office often marks the signing of significant bills by inviting advocates, lawmakers and the press to be present when they are signed.

Chandler was the first to publicly disclose the signing, posting to Twitter at 1:25 p.m. Thursday from the ceremony, "It's been signed into law!"

Education Secretary James Pesyer, Lt. Gov. Karyn Polito, several lawmakers, local students and representatives of the John F. Kennedy Presidential Library, the Edward M. Kennedy Institute for the U.S. Senate, Media Literacy Now, Teens Leading the Way, UTEC and Generation Citizen Massachusetts were all on hand for the event, according to a press release Baker's office sent out about an hour after the signing.

The new law says that American history, social science and civics must be taught in all public schools, including information on the state and U.S. constitutions and the Declaration of Independence, local history and government, the branches of government, the United States flag, disenfranchised voter populations, "the development of skills to access, analyze and evaluate written and digital media as it relates to history and civics," and "opportunities to identify and debate issues relative to power, economic status and the common good in democracy."

Chandler told the News Service the legislation aims to provide students with knowledge of the basics of government, then encourage them to use what they've learned to think critically. She pointed to the media literacy component as an example of those analytical skills.

"When they hear that famous term now, 'fake news,' they're going to be able to determine what is and what is not fake news," she said. "They're going to be able to look at the primary sources, to determine for themselves and not rely on someone else telling them it's fake news. That is an overused, abused term."

Tamara Sobel of the group Media Literacy Now said young people today live in a "media-centered world" where "not being able to detect true from false, bias, hype and commercially oriented messages versus real facts is disastrous for democracy."

The law also tasks Secretary of State William Galvin with developing a nonpartisan "high school voter challenge program" that will provide eligible students with opportunities to register or pre-register to vote.