The 29-year-old made 27 appearances for the Millers since joining from Bristol City in January 2017 and leaves for an undisclosed fee.
“Richard is an excellent keeper who has extensive experience of playing in the Championship and League One,” said manager Jimmy Floyd Hasselbaink.
“He has over 250 appearances under his belt and he is a good age for a keeper.
“Richard has a great attitude, he will be one of the leaders and a good influence in the dressing room and I am sure he will do well for us.”
O’Donnell was signed by the Millers last January but failed to convince boss Paul Warne with some inconsistent performances.
His arrival at Sixfields means loanee Matt Ingram returns to QPR.
“Matt has done really well for us and we would like to thank him for his efforts,” said Hasselbaink.
Defender Terence Kongolo has signed a four-year contract to join Huddersfield Town from Monaco.