The former Celtic and Tottenham midfielder, brought on as a second-half substitute, faced a difficult reintroduction to life in the Scottish Championship.
The Kenyan joined his former Celtic boss Lennon in the second tier on a free transfer earlier this week, a move dubbed by football fans as "one of the most random transfers ever."
After trailing 1-0 after half-time, Wanyama was introduced shortly after the hour mark, but the midfielder was sent off just 21 minutes later for a handball outside the box, denying Ayr United's Mark McKenzie a clear goal-scoring opportunity.
While Ayr United capitalised with further goals from Jamie Murphy and Ethan Walker, the focus inevitably fell on Wanyama's unfortunate debut.
The result leaves Dunfermline struggling just one place above the bottom spot.