Wargentin was the son of the vicar of Sunne Wilhelm Wargentin (1670-1735) and his spouse Christina Aroselia, and the great grandson of Joachim Wargentin (1611-1682), a Lübeck-born burgher of Åbo (Turku) in Finland.
When Pehr Wargentin was 12 years old he observed a (total) lunar eclipse which would spark his lifelong interest in Astronomy. During his tenure at Frösö trivialskola (elementary school), his teacher deemed him advanced enough to continue directly to Uppsala University. However, Wargentin's father wanted him first to attend the gymnasium (secondary school) of Härnösand, which he did. According to his own account, Wargentin was unimpressed with the purely classical and theological curriculum and the lack of any education in the sciences and did not finish the fourth year.
In 1735, Wargentin matriculated as a student at the University of Uppsala, where he excelled. Olof Hiorter was one of his instructors. He graduated with the degree of filosofie magister (then the highest degree awarded in the Faculty of Arts) in 1743 and became a docent in astronomy in 1746 and an adjunct in 1748. He was called to Stockholm as secretary of the Royal Swedish Academy of Sciences in 1749 on the death of secretary Pehr Elvius, Jr., and stayed on this post until his death. Wargentin therefore became the first long-serving secretary of the Academy, which had been founded in 1739. He is seen as an important person in leading the Academy to its first golden era. Wargentin also became the first director of the Stockholm Observatory founded by the Academy of Sciences on the initiative of his predecessor, Elvius, and completed in 1753. In 1756 Wargentin married Christina Magdalena Raab, a marriage that would produce three daughters until his wife's death due to a miscarriage in 1769. He was elected a Foreign Honorary Member of the American Academy of Arts and Sciences in 1781.
Wargentin made studies on the moons of Jupiter and published his first paper on the topic in 1741 in the Acta of the Royal Society of Sciences in Uppsala.
The crater Wargentin on the Moon is named after him, as is the secondary school Wargentinsskolan in Östersund, Jämtland, with a historical continuity going back to the school Wargentin himself attended on Frösön.
In his later career, Wargentin's focus shifted from astronomy to demography. The Swedish government decreed in 1736 that the clergy should maintain registers of all births and deaths in their parishes, and the concept emerged in the Swedish Royal Academy of Sciences that these parish data should be subjected to national analysis. Wargentin was assigned to lead this task nationally in 1754, and subsequently published a number of demographic articles in the Transactions of the Swedish Royal Academy, in particular "Mortaliteten i Sverige, i anledning af Tabell-Verket".