The Chairboys' veteran captain connected with substitute Danny Foster's cross to settle a hard-fought contest that saw Millers midfielder Jason Taylor sent off in stoppage time for kicking out at Stuart Beavon.
Wycombe started the brighter and came close to opening the scoring when Beavon collected Andy Sandell's lofted pass before his shot was kept out by Andy Warrington.
But the Chairboys took a deserved lead after 28 minutes when Foster's superb cross from the left was headed into the far corner by Ainsworth.
Wycombe goalkeeper Nikki Bull then produced an outstanding save to preserve his side's lead when he tipped Ryan Taylor's header from Nicky Law's cross onto the bar.
Wycombe then struck the woodwork themselves when Beavon found Kevin Betsy and his low shot across Warrington came back off the post and Jason Taylor's red card sealed the visitors' fate.