She is understood to be planning a career in the private sector.
Her decision to step down comes little more than a week since Labour's second successive landslide victory.
It was during Ms McDonagh's tenure as general secretary that strong accusations of "control freakery" were levelled at the party hierarchy.
The choice of party members to lead Labour into the Welsh Assembly elections and the London mayoral elections were both frustrated by electoral colleges.
A Blair loyalist, Ms McDonagh was appointed Labour's first female general secretary in 1998.
Explaining her decision to move on, she told the Times: "I told him [the prime minister] some time ago I would be leaving after the election.
"It's the right time for a change so that someone else can come in and start preparing for the next general election, which they will have to start thinking about quickly."
Sticking up for the party
The change comes hard on the heels of the creation of a new cabinet post of party chairman, taken by Charles Clarke the day after the general election.
But Ms McDonagh said her departure was not related to the new position: "When I'm gone there will still be a general secretary elected by the party and not appointed by the prime minister.
"Labour needs to have someone who will always stick up for it and think of the party first."
Officials speaking for the prime minister said: "Margaret has been a fantastic general secretary of the Labour Party who has always worked well with the prime minister.
"Her decision to leave is entirely her own and one which he fully understands."