Taylor Swift and Selena Gomez performed together for the first time on Tuesday, as the pair delivered Who Says to a sold out Madison Square Garden crowd.

Swift, who marked the end of the North American leg of her Speak Now world tour, was in the middle of the second night of her two sold out New York City shows, when Gomez, 19, made the surprise appearance.

Taylor, I think it's their turn to sing the song, Gomez says at one point.

Do you guys know it? she asks the crowd of screams and echoes.

Gomez was just one of two guests on Tuesday's grand finale. The legendary James Taylor also joined Swift on stage at Madison Square Garden, performing his hit Fire and Rain and providing the guitar part for Swift's ballad Fifteen.

Since the start of the Speak Now world tour, Swift has earned more than $40 million in ticket sales. While the North American leg is over, the country superstar is due back on stage in March, when she tours around Australia and New Zealand.

Speak Now, released more than one year ago, has sold more than 5.5 million copies worldwide, and has given Swift the most successful year of her career.

On Nov. 9, Swift took home top prize, Entertainer of the Year, at the annual CMA Awards. It was the second time Swift was honored with the title. In 2009, the Nashville native also took home the award.

On Sunday, Swift's award-winning year continued, as she was honored three times at the American Music Awards. There, Swift also took home the night's biggest award -- Artist of the Year -- beating out fellow nominees Adele, Lady Gaga, Lil Wayne and Katy Perry.

Swift, who turns 22 on Dec. 13, will have an early birthday present on Dec. 2, when Billboard honors her with a Woman of the Year award. Swift is the youngest artist to ever receive the award, joining past winners Fergie and Beyoncé.

Following Tuesday's Who Says duet, Gomez took to Twitter to share her excitement.

Performing at Madison Square Garden with my best friend was a highlight.. Congratulations Taylor on Speak Now tour, she wrote.

Swift, who was live-tweeting her show on Tuesday night, echoed the same enthusiasm.

I have so much to be thankful for this year. I'm leaving New York, replaying this tour in my mind. I love you all so much, Swift wrote.

Scroll down to watch a video of Taylor Swift and Selena Gomez performing Who Says.

Also Read: Is Taylor Swift's Next Single 'Ours'? [VIDEO]