Pathfinder is published by Paizo, which does not own the rights to Dungeons & Dragons. Those rights are the property of Wizards of the Coast, who currently publish the D&D "fifth edition", or 5e. But Pathfinder it is a spin-off from Dungeons & Dragons, specifically the "revised edition v.3.5", or 3.5e, and is extremely similar to that game in many ways. Playing a game of "3.PF", using material from both sets of rules, is quite possible and popular.
However, how and why this happened requires a history lesson.
D&D 3.5e and the open game license
Wizards of the Coast bought TSR, the company Gary Gygax founded to publish D&D, in 1997. At the time, D&D was in its second edition, known as AD&D 2e (the "A" stood for "Advanced", and there was also an Edition "basic"). Wizards published its own third edition (D&D 3e; Wizards dropped the basic / advanced) in 2000, and the "revised edition v.3.5" (D&D 3.5e) in 2004.
Wizards of the Coast also launched the founding of D&D 3e, and later D&D 3.5e, under the Open Game License, which was very, very open, about how much could be reused. This led to a huge explosion of third-party content for 3.5e, and 3.5e lived quite a long life as these things went on. There was plenty of material for it, the people who played it had become so used to dealing with, or even sticking to, their myriad problems.
At this time, Paizo published the Continue Y Dungeon magazines licensed by Wizards of the Coast. They also released a fair amount of their own adventures for the 3.5e rule set, under the Open Play License.
D&D 4e and the Unopened Gaming System License
Then in 2008 Wizards of the Coast released D&D 4e. The fourth edition of the game was a massive departure from previous D&D editions, and was extremely controversial. Many players did not want to switch to 4e, and continued to play 3.5e. Some even decided they didn't like Wizards of the Coast's D&D entirely, and went back to previous editions of TSR's D&D. And many played 4e, and there is some indication that 4e did relatively well in bringing new players into the game.
So D&D had fractured its fan base, and there were a lot of people playing D&D but not necessarily playing the D&D edition that Wizards of the Coast was publishing.
At the same time, Wizards of the Coast became much more possessive of their property. They didn't renew their Continue Y Dungeon licenses with Paizo, instead of publishing them internally, and they didn't release 4e under the OGL. Instead, they created and used the Game System License, which is vastly more restrictive than OGL. This made it almost impossible to develop third-party content for D&D 4e.
This placed Paizo in a very difficult situation: with his magazine revenue taken away, the latest issue of D&D hostile to third-party content, and the issue of D&D that was his daily bread, 3.5e, slowly aging and dying, they had a serious problem. They needed an answer, and they needed an answer. Quick.
Pathfinder, built on 3.5e open game content
Pathfinder was that answer. It was based on the D&D 3.5e open game content, and pushed hard to capture the market from people who refused to play 4e and stuck with 3.5e. By pledging 3.5e-but-better, and by delivering new content, Paizo could keep 3.5e alive, and thus continue to make adventure material and maintain that revenue stream.
This worked. Through a phenomenal advertising machine, Paizo could offer a game system that amounted to a few applications applied to 3.5e, call it "better" and capture a fairly large market share. It cost them relatively little to do it, and perhaps most importantly, they could do it very quickly: Pathfinder Core Rulebook It was released in August 2009, just a year and a half after D&D 4e. In contrast, Wizards of the Coast had spent 3 years on the basic rules for each of 3e and 4e. (It is not exactly clear when Paizo decided to start working on Pathfinder, but it was unlikely that it was before the announcement of 4e in 2007.)
Pathfinder allowed Paizo to continue publishing his adventure modules, which were his true focus and interest. Extensions to the Pathfinder system (classes, exploits, etc.) were enabled through low-paid freelancers with minimal editorial supervision, and allowed Paizo to keep Pathfinder "alive" through an overwhelming launch program, again at a relatively low cost. And so they could focus on selling adventures.
Aside: the "old school revival"
Paizo was not the only company noticing D&D's fractured fan base. Many other games, labeled "Old-School Rennaisance" or OSR, came out to try and capture players who dropped out of not only 4e, but also 3.5e. So in addition to Pathfinder being a 3.5e spin-off, there are other games that are spin-off or inspired by previous editions, before Wizards of the Coast bought TSR.
The death of D&D 4e
Pathfinder's history suggests that D&D 4e was a complete disaster; that's certainly the number of Pathfinder fans who watch it, and probably Paizo as well. It's not really accurate, though: D&D 4e did quite well, and again did particularly well with new players, relative to Pathfinder which focused primarily on older players who didn't like 4e.
As a game designer, I will also say that D&D 4e is easily one of the most strictly designed and executed RPGs out there. Other D&D editions aren't even playing in the same league. That's not all, 4e was excellent in itself, but that only matters if you like what it was trying to be, but much of 4e's criticism is based on rather shallow readings from the first book, rather than actually. gaming experience taking advantage of everything the system finally offered.
But there were also a number of very real problems. Part of this was poor planning, part of pressure from Hasbro (which owns Wizards of the Coast) to cut D&D costs, at least part was murder-suicide (!) By one of the leading developers of a 4e table virtual, killing not only him and his wife, but also that project and many of Wizards' plans for 4e.
In the end, 4e ended up losing the support of Wizards of the Coast. They tried to semi reboot it in 2010 with the "Essentials" line that was supposed to appeal to deactivated players due to the rather complicated process of building a 4e character, but for the most part it failed to attract much to real 4e players (which mostly did like the character creation process), and he couldn't get much attention from other aspiring gamers (who were mostly playing and mostly happy with Pathfinder). And between 2012, when Wizards announced they were going to do a new edition, and 2014, when the fifth edition was released, there was basically no new D&D content (unless you count the test packages for "D&D Next" as it was called beta system that would eventually become 5e). So even if you liked 4e, sooner or later the fact that there was new Pathfinder content and no new D&D content meant that a lot more people switched to Pathfinder.
D&D 5e: A return to form
Launched in 2014, D&D 5e was an attempt to reclaim the lost player base for Pathfinder and OSR. It undone a lot of changes made by D&D 4e. He embraced an "old school" style of play to a great extent. He also put a huge emphasis on being simple, easy to learn and play, and welcoming new players, which is not something any of the other games mentioned here can say.
And it has been extremely successful.
No numbers are known here, but Wizards has claimed that the past few years have been some of the best in D&D, and that dates back to the original editions of the 1970s and '80s that became an international phenomenon.
Pathfinder 2e: an amazing game
In 2019, Paizo released its second edition of Pathfinder. It is surprisingly 4e-like in various ways, which is somewhat ironic considering that Pathfinder was written as a response to 4e in the first place. (It also has a number of features similar to 5e, and of course many of them are unique.) Perhaps most notably, it's a huge departure from PF 1e, which vastly changes the game in many ways.
This has been controversial. The system is still fairly new, and the verdict is still out of place, but here is a risk for Paizo to follow in 4e's footsteps, clearly not his goal. However, time will have to count on that.