The win coupled with Tampa Bay's 4-0 loss to Boston means the Senators need just one point in their final three games to clinch a playoff spot.
The win also snapped a five-game losing streak for Ottawa and was just its third victory in its past 12 games.
Jimmy Howard made 22 saves in the loss for the Red Wings, who are playing out the string as they will miss the playoffs for the first time in 25 seasons.
Clarke MacArthur made his season debut for the Senators and played his first game since Oct. 14, 2015, because of concussion issues.
Earlier this year, Ottawa general manager Pierre Dorion said MacArthur had been shut down for the season when MacArthur failed the necessary concussion baseline test in January.
Last week while the Senators were on the road he passed another baseline test.
MacArthur played just under 10 minutes.
Despite being outshot 11-6 in the first period, Ottawa escaped the opening period with a 1-0 lead at 12:59 thanks to its captain.
Karlsson carried the puck in from the blue line and just before he reached the goal line at the outer edge of the faceoff circle, he took a shot that found the tiniest of openings between Howard's shoulder and the crossbar.
It was a different story on the shot clock in the second, but the part that matters most was the same.
Ottawa outshot the Red Wings 12-3 in the second, but another sharp-angle goal, this one from Pyatt, was the only marker of the period.
On a broken play inside the Detroit zone, Pyatt picked up a loose puck and shot from the bottom of the faceoff circle through the legs of Howard and in at 7:49 giving the Senators a 2-0 lead.
NOTES: Marc Methot, Cody Ceci, Bobby Ryan, Zack Smith, Jyrki Jokipakka, Chris Neil, Chris DiDomenico and Colin White were scratches for the Ottawa Senators on Tuesday. ... Drew Miller, Anthony Mantha and Luke Glendening were the scratches for the Red Wings. ... Detroit won the previous three meetings this season with the Senators, once in regulation, once in OT and Monday in a shootout. ... Senators defenseman Dion Phaneuf played in his 900th NHL game Tuesday. ... Red Wings goaltender Jimmy Howard played in his 400th NHL game Tuesday.
Red Wings: Host Canadiens on Saturday night.
Senators: Travel to Boston to face the Bruins on Thursday night.