Carney's deputy, Josh Earnest, will take his place, the president said.
Obama interrupted Carney on the podium, where he was answering questions during the White House daily news briefing, catching reporters by surprise.
"One of Jay's favorite lines is, 'I have no personnel announcements at this time,'" said Obama.
"But I do, and it's bittersweet," he said.
It was Obama's second turn on the podium on Friday. Earlier, he spoke in the same spot to say his Veteran Affairs Secretary Eric Shinseki had resigned.
Obama called Carney one of his closest friends and advisers, and said he was "not thrilled" when Carney first told him in April that he wanted to leave.
Carney, 49, has been press secretary for longer than usual for such a high-pressure job. Many occupants stay for only a couple of years before leaving.
Carney replaced Robert Gibbs in January 2011 and stayed on through Obama's 2012 re-election.
Earlier in Obama's administration, Carney was Vice President Joe Biden's communications director. Before then, he was a reporter for 21 years, including a turn as Moscow bureau chief for Time magazine.
Carney frequently harkened back to his own time as a White House correspondent for Time magazine in commenting on the reporting techniques of the current press corps, which he said he sometimes found overly dramatic.
He and his wife, ABC news correspondent Claire Shipman, have two young children.
Obama noted that Carney's designated successor, Earnest, ran communications during the Iowa caucuses in Obama's first presidential campaign in 2008.
"Josh is an earnest guy," Obama quipped, "and you can't find just a nicer individual." The president called Earnest, 39, "a straight shooter and a great guy."
After Obama left the podium, Carney told reporters that he hasn't made any decisions yet about his next job but has had some conversations during the past few months about new possibilities.
He said he first planned to spend the summer with his children.