On 27 April 2011, the New York Islanders signed Nilsson to a three-year entry-level contract. Nilsson 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 2 July 2016, Nilsson as a restricted free agent was traded from the 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 1 July 2017. During the 2018–19 season, on 2 January 2019, he was traded by the Canucks along with Darren Archibald to the Ottawa Senators in exchange for Mike McKenna, Tom Pyatt and a sixth-round draft pick in 2019. He was acquired by the Senators following injuries to goaltenders Mike Condon and Craig Anderson. In 22 starts for the Senators, Nilsson went. On 29 May 2019, the Senators re-signed Nilsson to a two-year, $5.2 million contract extension with an annual average of $2.6 million.
Nilsson is married to Emelie Nevanperä and they have one child together. Nilsson has another son from a previous relationship with Fernanda Nilsson. Nevanperä also has a child from a previous relationship. For his son's second birthday he dressed up as Spider-Man. On 8 November 2017, Nilsson announced the birth of his son on his official Instagram. Nilsson is an open supporter of the LGBT+ community. While with the Buffalo Sabres, he became the first NHL goaltender to put a rainbow flag on their mask.