A reliable reliever for the first four years of his career, Ayala has dipped to 1-8 with a 5.77 ERA this season. He's appeared in 62 games, which ranks among the major league leaders.
Missing injured closer Billy Wagner, the NL East-leading Mets are having trouble nailing down games. Ayala should provide depth and another late-inning option for manager Jerry Manuel.
In return, New York is expected to send minor leaguer Anderson Hernandez to Washington once he clears waivers. A smooth-fielding middle infielder, Hernandez has a .138 career average in 87 big league at-bats.
"I'm surprised. It's a little bit late for a trade," Ayala said in Washington. "But for me, I passed my best times in this organization."
The 30-year-old Ayala was the longest-tenured Nationals player, having joined the club in 2003 when it was located in Montreal. He was 26-24 with a 2.82 ERA and nine saves in 258 appearances from 2003-07. He missed the 2006 season following elbow surgery, then returned to the mound last year and went 2-2 with a 3.19 ERA in 44 games.
"Sometimes guys just have off years. ... He's certainly healthy, and I think a change of scenery will help him," Nationals general manager Jim Bowden said. "I think going to a pennant race will help him.
"I can't say enough good things about Luis. He took the ball for us anytime he was asked and did a phenomenal job his entire career. He'll be missed."
New York general manager Omar Minaya is familiar with Ayala from his days as GM of the Montreal Expos.
"He had requested to be traded this year throughout the year," Bowden said. "We attempted to do so by the (non-waiver) trade deadline and just were not able to make a deal that made sense for us. With a month and a half left before free agency ... we felt we needed to get something for him."
The Mets claimed Ayala off waivers and the teams worked out a deal. New York entered Sunday with a two-game edge in the NL East over Philadelphia.
"They're fighting for first place, so I'm going to do my best to clear my mind and try to help the bullpen," Ayala said.
Ayala pitched two scoreless innings against the Mets on Wednesday during New York's 12-0 victory at last-place Washington.