The multihour event held on the Great Lawn in New York's Central Park also featured Vice President Joe Biden, Hugh Jackman, Bono, Leonardo DiCaprio and Pearl Jam, who closed the event with a rocking performance.
Obama first appeared in a video promoting the 62 Million Girls campaign, but she later walked onstage after Beyonce introduced her following her performance.
"Let's give it up for the amazing Beyoncé," Obama said. "I am thrilled to be here tonight ... and honored to follow a woman who I admire and adore."
Obama said she has traveled the world and met with young women who have not had a chance to receive an education. She asked the audience to tweet photos of themselves with the hashtag #62MillionGirls and say what you learned in school. Obama said she learned how to "speak up" in school.
"Right now 62 million girls are not in school ... they deserve the same chances to get an education as my daughters and your daughters," she told the feverish audience, who cheered her on.
President Barack Obama also appeared in a video at the event, in its fourth year and aimed at ending poverty around the world. The festival is timed to coincide with the U.N. General Assembly meeting, and fans earned free tickets by taking actions to end poverty on globalcitizen.org.
Yousafzai, the 18-year-old Pakistani activist, was passionate as she spoke about fighting for the right for all children to receive an education.
"I want education to be the top priority because how can we end poverty ... when we deny the right to education," she said. "It's not that there is lack of money in this world ... we have billions and trillions of dollars, but where the money goes is military, it's things that are useless and that are not useful to society."
"It is a book and a pen that can change the life of a child — it's not a gun," Yousafzai added. "It was a gun that hit me on the left side of my forehead, it was a gun that hit my two friends, but it wasn't a pen. But it was a pen (that) really helped us go forward in our lives."
The event, which aired on MSNBC, was hosted by Stephen Colbert, Kerry Washington, Salma Hayek Pinault, Olivia Wilde and other top celebrities. Usher, Jason Sudeikis, Laverne Cox, Katie Holmes, Facebook CEO Mark Zuckerberg and Bill and Melinda Gates also attended the event, along with multiple world leaders, including U.N. Secretary-General Ban Ki-moon.
Backstage was just as star-studded: Everyone from Daniel Craig to Jay Z — holding daughter Blue Ivy — was there.
The event featured a number of unique musical collaborations: Beyonce joined Eddie Vedder onstage; Sting performed with rapper Common; and Ariana Grande sang with Coldplay.
Sheeran even joined Beyonce for a guitar-based version of her thumping R&B hit "Drunk In Love," which earned roaring applause.
Beyonce, who changed three times during her set, performed hits from "Crazy In Love" to "Halo" to "Single Ladies."
"I want y'all to feel the connection right now ... I want y'all to get lost and dance like children," she told the crowd.