The 25-year-old joined City in January 2015 from Crystal Palace for an undisclosed fee and has since made 33 appearances, scoring twice.
"I'm delighted to get this done and dusted," said the ex-Southend trainee.
"I've enjoyed my time at City, especially the last eight months, so we can move on now and look forward."
O'Keefe added: "Hopefully we can keep pushing and improving as a squad and get ourselves back in the Premier League."
Midfielder Stuart O'Keefe has signed a new contract at Cardiff City which will keep him with the Bluebirds until the summer of 2019.