Name changes are just awkward, and there's no real perfect way to handle them.
The general standard is to record names as they were at birth. For example, in genealogies women are usually recorded under their maiden name not their married name. In the interest of equality I see no reason why the same principle should not apply to men who change their name.
In my genealogy software, I record all people by their name at birth. However, this may not mean the exact spelling on the birth certificate or baptism record. For example, I have an ancestor called William Baxter. His baptism reads "William Backster". All other records for him and his siblings are spelled Baxter. The clerk just didn't know how to spell very well, and his name properly spelled is William Baxter, so that's how I entered him into my genealogy software. But "properly" is always going to be a bit subjective, so it's a judgement call.
I have a relative who was an actor, who used a stage name. He was much better known by the stage name, and subsequently legally changed his name. It's a dilemma as to which name to use as the primary name in my genealogy software since his birth name bears no resemblance to his stage name. I decided on his birth name, mainly for consistency. But in an online tree, people searching for him will probably search under his better known name.
Most genealogy software allows you to enter "alternative names" or "aliases" as events/facts for individuals. I use this for adoptions, major spelling changes, or name changes.
In your case, I would enter him in my genealogy software as Peter Svensson, and add Johansson as an alternative name. I have seen people invent names in this type of case, such as saying his surname was Svensson-Johansson. If he never used this hyphenated name then I would argue that this is a wrong way of recording his name. However, this is just my preference and there may be good arguments for doing it in other ways.