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.
Pedro stepped off the bench to send Chelsea into the FA Cup semi-finals after they beat Leicester 2-1 at the King Power Stadium on Sunday evening.
RB Leipzig came from behind at the Red Bull Arena to end a run of four winless games and defeat Bundesliga leaders Bayern Munich 2-1 on Sunday.