I think there's something fundamental missing from all the other answers so far: the modern realization that *topological spaces* are distinct from *$\infty$-groupoids*.

Suppose you didn't know about higher homotopy groups at all. In fact, suppose you didn't even know about the fundamental group, and maybe you didn't even know about the notion of *homotopy*! Here's a way they could have been invented. Many of the other answers touch on parts of this story, but I think the whole thing together gives us additional insight.

You may or may not be familiar with the notion of $\infty$-groupoid. Technically it's complicated, but intuitively I think it is (or should be) quite simple: it's just about taking seriously the idea that any "collection of things" can, and often should, come with a notion of "isomorphism" or "sameness" between any two of those things -- and that those isomorphisms are again a "collection", hence can come with their own notion of isomorphism, *ad infinitum*. In more algebro-geometric language, an $\infty$-groupoid is the natural sort of "thing" for a moduli space to be: you have some things, and you specify when some of those things are the same as each other, and then you specify when some of those "samenesses" are the same as each other, and so on.

Fundamental examples of $\infty$-groupoids arise by repeatedly considering collections *of* sets and set-like objects. The collection of all sets is (ignoring questions of size, i.e. proper-class-ness or not) best regarded not as a set but as a groupoid, since usually we care not whether two sets (or objects built out of sets like groups, rings, fields, topological spaces, etc.) are "equal" in the sense of having exactly the same elements, but whether they are isomorphic. A groupoid is just an $\infty$-groupoid in which no two "ways that two objects are the same" can themselves be the same in any nontrivial way. But for similar reasons, the collection of groupoids is naturally regarded as a 2-groupoid, which is trivial after the "ways that two samenesses are the same" level; the collection of 2-groupoids is a 3-groupoid; and so on. This doesn't get you all the way to $\infty$-groupoids by induction, but it's natural to want a context in which $n$-groupoids live for all $n$ simultaneously, and moreover at the infinity point it stabilizes: the collection of $\infty$-groupoids is another $\infty$-groupoid.

Now an $\infty$-groupoid is a rather complicated structure, so when working with them it's useful to be able to extract simpler invariants. One obvious useful invariant is the set of isomorphism classes of objects, $\pi_0(G)$ (the "coarse moduli set"). And since the set $G(x,y)$ of isomorphisms between any two objects of an $\infty$-groupoid is again an $\infty$-groupoid, we can also form $\pi_0(G(x,y))$, and also $\pi_0(G(x,y)(f,g))$ and so on. However, if $x$ and $y$ are not isomorphic then $G(x,y)$ is empty, while if they are isomorphic then $G(x,y) \simeq G(x,x)$ by composing with any isomorphism $x\cong y$. Thus, "all the information" is carried by applying this only to automorphisms, giving $\pi_0(G(x,x))$, $\pi_0(G(x,x)(\mathrm{id}_x,\mathrm{id}_x))$, and so on: these are the "homotopy groups" $\pi_1(G,x)$, $\pi_2(G,x)$, etc. The sense in which this is "all the information" is that a map of $\infty$-groupoids $f:G\to H$ is an equivalence if and only if it induces isomorphisms on $\pi_n$ for all $n\ge 0$.

Note that I haven't said anything about "topological spaces" or "weak homotopy equivalence" yet. The last sentence of the previous paragraph is a *theorem* about objects called "$\infty$-groupoids" that can be motivated and justified on grounds completely independent from topology.

The topology enters the picture by way of a functor $\Pi : \mathrm{Top} \to \infty \mathrm{Gpd}$ called the *fundamental $\infty$-groupoid* of a topological space. The $\infty$-groupoid $\Pi X$ can be built explicitly by saying "take its points to be points of $X$, its isomorphisms $x\cong y$ to be paths in $X$, its 2-isomorphisms to be homotopies in $X$, and so on." We then define the homotopy groups of $X$ to be those of its fundamental $\infty$-groupoid, $\pi_n(X,x) = \pi_n(\Pi(X),x)$, and define a continous map $f:X\to Y$ to be a *weak homotopy equivalence* if $\Pi f : \Pi X \to \Pi Y$ is an equivalence. Then we can observe that for a large class of spaces, such as CW complexes, weak homotopy equivalences coincide with *homotopy equivalences*, and fundamental groups have useful relations to homology, obstruction theory, etc.

However, the construction of $\Pi$ can be motivated in an even more basic way, that doesn't depend on deciding for some other reason that "paths and homotopies" in a space are interesting, or that spaces built by attaching cells are interesting. Note that a bare set can be regarded as an $\infty$-groupoid with no nontrivial isomorphisms, but also as a topological space with the discrete topology. Thus, it's not unreasonable to imagine that there might be a category $\mathcal{T}$ (or more precisely an $\infty$-category) that contains topological spaces and $\infty$-groupoids as full subcategories whose *intersection* consists of the bare sets. In general, the objects of $\mathcal{T}$ will be sets that have "both topology and $\infty$-groupoid structure". For instance, the groupoid *of topological spaces* naturally inherits topologies on its spaces of isomorphisms; hence it is a "topological 2-groupoid" which is a particular object of $\mathcal{T}$.

There is more than one way to construct such a category $\mathcal{T}$. However, what they have in common is that while the inclusion $\mathrm{Top} \to \mathcal{T}$ does not preserve all colimits, it does at least preserve *unions of open subsets*. That is, if a space $X$ is the union of open subspaces $X = \bigcup_i U_i$, then the diagram consisting of all the inclusions $U_i \to X$ is a colimiting cone in $\mathcal{T}$ under the diagram consisting of the spaces $U_i$ and all of their intersections $U_i\cap U_j$, $U_i\cap U_j\cap U_k$, etc. This should seem reasonable if you recall that the very *notion* of topological space is (or can be) defined in terms of open subsets that are closed under arbitrary unions: we're just saying that the inclusion $\mathrm{Top} \to \mathcal{T}$ respects the "basic building blocks of topology".

Now it turns out that the other inclusion $\infty \mathrm{Gpd} \to \mathcal{T}$ is a *reflective* subcategory (sub-$\infty$-category), i.e. the inclusion functor has a left adjoint, which I will denote ʃ. What this means is that if $X$ is a topological space and $G$ an $\infty$-groupoid, then morphisms $X\to G$ in $\mathcal{T}$ are equivalent to maps of $\infty$-groupoids ʃ $X \to G$.

Why is this interesting? Well, it's reasonable to view a map $X\to G$ as a "family of objects of $G$ parametrized continuously by $X$". If this needs further motivation, consider that if $X$ and $Y$ are both spaces, then a map $X\to Y$ is certainly a "family of *points* of $Y$ parametrized continuously by $X$". Now generalize this to the case when $Y$ is an arbitrary object of $\mathcal{T}$. For instance, if $Y$ is the groupoid of topological spaces, regarded as an object of $\mathcal{T}$ as mentioned above, then a map $X\to \mathcal{T}$ is exactly a fiber bundle over $X$: a family of topological spaces (the fibers) "continuously parametrized by $X$". Now specialize to the case when $Y$ lies in $\infty\mathrm{Gpd}$. For instance, if $G$ is the groupoid of sets, then a map $X\to G$ is "a continuously $X$-indexed family of sets", which happens to coincide with a *covering space* of $X$. Thus, the reflectivity of $\infty \mathrm{Gpd}$ says that the $\infty$-groupoid ʃ $X$ contains all the information about $X$-indexed families of objects of (non-topological) $\infty$-groupoids.

Now it happens -- as a *theorem*, not a definition -- that this left adjoint reflector ʃ *turns out to be the fundamental $\infty$-groupoid*! In other words, even if you don't know why to care about paths and homotopies, if you only know to care about topological spaces and $\infty$-groupoids, and want to talk about them in a natural common context that respects the basic building blocks of topology, and to talk about objects of $\infty$-groupoids indexed continuously by spaces, then you are essentially forced to notice the fundamental $\infty$-groupoid, and therefore also the higher homotopy groups.

By the way, the fundamental group $\pi_1$, which you seem to believe in already, appears in this story by restricting to 1-groupoids. It happens that the subcategory of 1-groupoids is reflective in $\infty$-groupoids, and the reflector applied to $\Pi X$ builds the usual "fundamental groupoid" $\Pi_1(X)$ whose isomorphisms are homotopy classes of paths in $X$. The universal property of this reflector means that $\Pi_1(X)$ carries all the information about families of objects of 1-groupoids parametrized continuously by $X$. In particular, applying this to the 1-groupoid of sets, we find that a "family of sets parametrized by $X$" is essentially a covering space of $X$, and so $\Pi_1(X)$ classifies covering spaces. And if $X$ is connected, then $\Pi_1(X)$ is essentially determined by $\pi_1(X)$.

To conclude, I must admit that the last four paragraphs began with a lie. There is no version of $\mathcal{T}$ that contains *all* of $\mathrm{Top}$ as a full subcategory and for which $\infty \mathrm{Gpd}$ is honestly reflective. There are versions of $\mathcal{T}$ (e.g. "continuous $\infty$-groupoids") that contain all "spaces built out of copies and open subsets of $\mathbb{R}^n$'s" and in which $\infty \mathrm{Gpd}$ is honestly reflective. There are also versions of $\mathcal{T}$ (e.g. "$(\infty,1)$-topoi") that contain all topological spaces, but in which the reflector ʃ is only defined on a (large) class of "nice" topological spaces. In the latter case, one can still define a "shape" ʃ $X$ of a non-nice space $X$ that "carries all the information about $X$-indexed families of objects of $\infty$-groupoids", but it is in general only a "pro-$\infty$-groupoid"; this includes for instance the information carried by the pro-discrete étale fundamental group.

Further reading (and shameless self-citations):

- philosophical introduction to $\infty$-groupoids: section 2 of this paper
- the above story told specifically about $(\infty,1)$-toposes: blog post
- a similar version told for other versions of $\mathcal{T}$ (skip over the type theory): section 5 of this paper, and the introduction to this one