Ryan beat Bruins goalie Chad Johnson with a backhander under the crossbar to break a 3-3 tie.
It came only moments after the Bruins were denied the lead when Jarome Iginla's apparent goal was waved off following a video review that determined he had kicked in the puck.
Zack Smith, Patrick Wiercioch and Cory Conacher also scored for the Senators, who won for just the second time in six games.
Craig Anderson logged 29 saves.
Boston got goals from Iginla, Daniel Paille and David Warsofsky, but fell for the first time in four games.
Tuukka Rask was lifted in the second period after allowing three goals on 12 shots.
Johnson relieved and turned aside 16-of-17 shots the rest of the way.