Princeton University has announced its first black valedictorian in its 274-year history.

Nicholas Johnson, who was named valedictorian of Princeton’s Class of 2020, called the achievement especially significant, given Princeton’s struggle in recent years, like numerous other prestigious universities, to confront its troubled history with slavery.

He said he was stunned when he learned last week that he was the university’s first black valedictorian.

“Being Princeton’s first black valedictorian is very empowering, especially given its historical ties to the institution of slavery,” Mr. Johnson, 22, said.

He added that he felt the university, as a primarily white institution, had “very much been a leader amongst its peer institutions” and “very critical and cognizant about its ties to slavery.”

“They’ve taken very deliberate steps to reconcile things,” he said.

With Princeton’s in-person graduation ceremony canceled because of the coronavirus pandemic, it will hold a virtual one on May 31. The school plans on having an in-person ceremony for the Class of 2020 next spring, in May 2021.

Mr. Johnson, who is from Montreal, majored in operations research and financial engineering.

He wrote his senior thesis on developing algorithms to design a community-based preventive health intervention to decrease obesity in Canada. The research also included applications to help impose strict social distancing to help stop the spread of the coronavirus.

Mr. Johnson, a member of the Princeton chapter of Engineers Without Borders, said he had summer internships both at Google and at Oxford University.

Mr. Johnson, a basketball enthusiast and Toronto Raptors fan, also loves playing chess and having discussions, whether on academics or on race, with fellow students at Princeton.

“I’ve had many critical conversations with classmates on campus about their thoughts on Princetons’ legacy and how it affects their daily life as students, and what we can do to create a college environment in which students who look like us can thrive,” he said.

On becoming the university’s first black valedictorian, he said, “I hope this achievement serves as inspiration to black students coming up behind me.”