On 27 April 2011, the New York Islanders signed Nilsson to a three-year entry-level contract.
He made his NHL debut on 19 November 2011, against the Boston Bruins, in relief of Rick DiPietro. He let in 3 goals on 17 shots, while playing 40 minutes, as the Islanders lost 6-0. He got his first start in the NHL on 21 November 2011, against the Pittsburgh Penguins at Consol Energy Center in Pittsburgh, Pennsylvania. On 4 March 2012, he earned his first NHL victory and shutout in a 1-0 home win against the New Jersey Devils. In doing so, he became the first goalie in Islanders history to record a shutout for his first win. In his next start, on 10 March 2012, he almost shutout the Devils a second time, but the Devils scored two goals in the last two minutes of the game, resulting in a 2-1 loss for the Islanders.
Nilsson saw limited action with the Bridgeport Sound Tigers in 2012–13, as he was diagnosed with an unknown, fatigue-inducing illness in January 2013. The illness was later determined to be a vitamin B12 deficiency.
Nilsson spent much of the 2013–14 season as the Islanders' backup goaltender.
On 26 May 2014, as a restricted free agent, Nilsson decided to sign a contract with Russian club, Ak Bars Kazan of the Kontinental Hockey League. Ak Bars issued a release confirming the signing. On 4 October 2014, Nilsson's NHL rights were traded by the Islanders to the Chicago Blackhawks in a trade for Nick Leddy.
On 6 July 2015, Nilsson's NHL rights were traded for a second time, from the Blackhawks to the Edmonton Oilers in exchange for prospect Liam Coughlin. He in turn agreed to a one-year, one-way contract with the Oilers. Nilsson earned a spot on the Oilers roster after a stellar training camp, not allowing a single goal in the preseason. In the 2015–16 season, Nilsson appeared in a career high 26 games with the Oilers, sharing the pipes with Cam Talbot, before he was traded approaching the trade deadline by the Oilers to the St. Louis Blues in exchange for Niklas Lundström and the Blues fifth round selection in the 2016 NHL Entry Draft on 27 February 2016.
On July 2, 2016, Nilsson as a restricted free agent was traded from the St. Louis Blues to the Buffalo Sabres in exchange for a 2017 fifth round draft pick. During the 2016–17 season, in December 2016, Nilsson began wearing a mask with a gay pride flag painted on the back as a sign that ice hockey welcomes diversity. He drew praise from Wade Davis, executive director of the You Can Play campaign, who said that Nilsson "is taking a risk on multiple fronts and is standing up for something that he believes in, knowing the backlash that could come his way."
After a successful tenure with the Sabres, serving as backup to Robin Lehner, Nilsson left as a free agent in signing a two-year, $5 million contract with the Vancouver Canucks on July 1, 2017.
Nilsson represented Sweden at the 2010 World Junior Ice Hockey Championships which were held in Saskatchewan, Canada. He only played in one game during the tournament, as Jacob Markström was the starter. Sweden won a bronze medal at the tournament.